From: chsc at peytz dot dk Operating system: Linux PHP version: 5.3.0alpha2 PHP Bug Type: PDO related Bug description: PDOStatement->setFetchMode() forgets FETCH_PROPS_LATE
Description: ------------ PDO::FETCH_PROPS_LATE only works if it specified in both the $stmt->setFetchMode() call and in the following $stmt->fetch(). Calling $stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'MyClass'); $obj = $stmt->fetch(); yields the same result as $stmt->setFetchMode(PDO::FETCH_CLASS, 'MyClass'); $obj$stmt->fetch(); In order to make it work you should specify FETCH_PROPS_LATE in both calls, i.e. $stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'MyClass'); $obj = $stmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE); Reproduce code: --------------- class Person { public $name = NULL; public function __construct() { var_dump($this->name); } } $db = new PDO("mysql:dbname=foo", "foo", "secret"); $db->exec("CREATE TABLE person (id INTEGER NOT NULL, name VARCHAR(100))"); $db->exec("INSERT INTO person (id, name) VALUES (1, 'Sven')"); $stmt1 = $db->query('SELECT * FROM person'); $stmt1->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person'); $obj1 = $stmt1->fetch(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE); var_dump($obj1->name); $stmt1 = NULL; $stmt2 = $db->query('SELECT * FROM person'); $stmt2->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Person'); $obj2 = $stmt2->fetch(); var_dump($obj2->name); Expected result: ---------------- NULL string(4) "Sven" NULL string(4) "Sven" Actual result: -------------- NULL string(4) "Sven" string(4) "Sven" string(4) "Sven" -- Edit bug report at http://bugs.php.net/?id=46139&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46139&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46139&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46139&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46139&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=46139&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46139&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46139&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46139&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46139&r=support Expected behavior: http://bugs.php.net/fix.php?id=46139&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46139&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46139&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46139&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46139&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46139&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46139&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46139&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46139&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46139&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46139&r=mysqlcfg