#37134 [NEW]: PDOStatement::fetchObject calls constructor after populating fields

From: Date: Wed, 19 Apr 2006 09:29:49 +0000
Subject: #37134 [NEW]: PDOStatement::fetchObject calls constructor after populating fields
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-95977@lists.php.net to get a copy of this message
From: mark-phpbugs at vectrex dot org dot uk Operating system: Linux PHP version: 5.1.3RC2 PHP Bug Type: PDO related Bug description: PDOStatement::fetchObject calls constructor after populating fields Description: ------------ PDOStatement::fetchObject calls constructor after populating fields, which is not what I expected. I expected it to call __construct() first, then populate fields. Reproduce code: --------------- <?php /* Test case for PDOStatement::fetchObject('ClassName') * Vars populated before constructor is run. */ $db = new PDO("sqlite::memory:"); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->exec("CREATE TABLE person (id INTEGER NOT NULL, name varchar(100))"); $db->exec("INSERT INTO person(id, name) VALUES (1, 'Fred')"); class Person { var $id; var $name; function __construct() { $this->id = -1; } } $st = $db->query('SELECT * FROM person'); $fred = $st->fetchObject('Person'); print_r($fred); ?> Expected result: ---------------- $fred->id should be 1 As the constructor will be called before variable population. Actual result: -------------- $fred->id is -1 Because the constructor is called after variable population. -- Edit bug report at http://bugs.php.net/?id=37134&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37134&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=37134&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37134&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=37134&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=37134&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=37134&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=37134&r=needscript Try newer version: http://bugs.php.net/fix.php?id=37134&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=37134&r=support Expected behavior: http://bugs.php.net/fix.php?id=37134&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=37134&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=37134&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=37134&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37134&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=37134&r=dst IIS Stability: http://bugs.php.net/fix.php?id=37134&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=37134&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=37134&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=37134&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=37134&r=mysqlcfg

« previous php.bugs (#95977) next »