From: riccardo dot bonciani at cinic dot it Operating system: Linux Gentoo PHP version: 5.2.4 PHP Bug Type: PDO related Bug description: FETCH_CLASS
Description: ------------ By using FETCH_CLASS and __set overloading, __construct will be executed after populating object properties; Reproduce code: --------------- class Test { protected $prop; function __construct() { $this->prop['a'] = null; $this->prop['b'] = null; $this->prop['c'] = null; } function __set($name, $value) { $this->prop[$name] = $value; } } $query = "SELECT 1 AS a, 2 AS b, 3 AS c"; $sth = $objPDO->prepare($query); $sth->execute(); $result = $sth->fetchAll(PDO::FETCH_CLASS, 'Test'); var_dump($result); Expected result: ---------------- I expect array(1) { [0]=> object(Test)#8 (1) { ["prop:protected"]=> array(3) { ["a"]=> string(1) "1" ["b"]=> string(1) "2" ["c"]=> string(1) "3" } } } Actual result: -------------- array(1) { [0]=> object(Test)#8 (1) { ["prop:protected"]=> array(3) { ["a"]=> NULL ["b"]=> NULL ["c"]=> NULL } } } Try to comment __construct code and you'll obtain the right result. -- Edit bug report at http://bugs.php.net/?id=43160&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43160&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43160&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43160&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43160&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43160&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43160&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43160&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43160&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43160&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43160&r=support Expected behavior: http://bugs.php.net/fix.php?id=43160&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43160&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43160&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43160&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43160&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43160&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43160&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43160&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43160&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43160&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43160&r=mysqlcfg