Bug #76283 [Opn->Nab]: PDO fetch not throw exception when fetch_type not correct

From: Date: Sat, 28 Apr 2018 10:14:34 +0000
Subject: Bug #76283 [Opn->Nab]: PDO fetch not throw exception when fetch_type not correct
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214963@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76283&edit=1 ID: 76283 Updated by: requinix@php.net Reported by: jaylecn at foxmail dot com Summary: PDO fetch not throw exception when fetch_type not correct -Status: Open +Status: Not a bug Type: Bug Package: PDO Core Operating System: WIN PHP Version: 7.2.5 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Read the documentation for PDOStatement::fetch/fetchAll and you'll see FETCH_CLASSTYPE is not one of the options listed for the $fetch_type. PDO::FETCH_CLASSTYPE is merely a number. It happens to be the same number as some other PDO constants. Other PDO constants that *are* valid for $fetch_type. Previous Comments: ------------------------------------------------------------------------ [2018-04-28 10:07:44] jaylecn at foxmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=76283&edit=1

« previous php.bugs (#214963) next »