Bug #76283 [NEW]: PDO fetch not throw exception when fetch_type not correct
| From: | jaylecn at foxmail dot com | Date: | Sat, 28 Apr 2018 10:07:47 +0000 |
| Subject: | Bug #76283 [NEW]: PDO fetch not throw exception when fetch_type not correct | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-214962@lists.php.net to get a copy of this message | ||
From: jaylecn at foxmail dot com
Operating system: WIN
PHP version: 7.2.5
Package: PDO Core
Bug Type: Bug
Bug description:PDO fetch not throw exception when fetch_type not correct
Description:
------------
PDO::FETCH_CLASSTYPE/PDO::FETCH_SERIALIZE can only be used together with
PDO::FETCH_CLASS
https://github.com/php/php-src/blob/php-7.2.3/ext/pdo/pdo_stmt.c#L1225
it should be throw exception, but
1. if use PDOStatement::setFetchMode(), will throw exception
2. if use PDOStatement::fetch(), fetch type will reset to
PDO::ATTR_DEFAULT_FETCH_MODE
3. if use PDOStatement::fetchAll(), fetch type will reset to
PDO::FETCH_BOTH
Test script:
---------------
$statement = $pdo->prepare("SELECT * FROM foo");
$statement->execute([]);
// will throw exception
$statement->setFetchMode(PDO::FETCH_CLASSTYPE);
$row = $statement->fetch();
// fetch type reset to PDO::ATTR_DEFAULT_FETCH_MODE
$row = $statement->fetch(PDO::FETCH_CLASSTYPE);
// fetch type reset to PDO::FETCH_BOTH
$lists = $statement->fetchAll(PDO::FETCH_CLASSTYPE);
Expected result:
----------------
see test script
Actual result:
--------------
I think all these three method should throw exception, but it's not
it's a Feature ?
--
Edit bug report at https://bugs.php.net/bug.php?id=76283&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76283&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76283&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76283&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76283&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76283&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76283&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76283&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76283&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76283&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76283&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76283&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76283&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76283&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76283&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76283&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76283&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76283&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76283&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76283&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76283&r=mysqlcfg