From: [EMAIL PROTECTED] Operating system: PHP version: 5.2.6 PHP Bug Type: PDO related Bug description: Fetching results using PDO::FETCH_CLASS set attributes before calling ctor
Description: ------------ If you set the PDO fetch mode to PDO::FETCH_CLASS and fetch all results from a result set (aka processed statement), the constructor is called after the properties of the newly created object are set. This is incorrect from the OO point of view, since the ctor may provide sensible default values for properties and prepare the object overall. Therefore property manipulation should happen after the ctor was called. Reproduce code: --------------- $db = $this->getTrackbackDbConection(); $select = $db->query( 'SELECT ... ;' ); $select->setFetchMode( PDO::FETCH_CLASS, 'myCustomClass' ); $result = $select->fetchAll(); class myCustomClass { public $someProperty; public function __construct() { $this->someProperty = 'default' } } Expected result: ---------------- myCustomClass->$someProperty is overwritten by a value from the database. Actual result: -------------- myCustomClass->$someProperty is overwritten by 'default' since __construct() is called after the properties have been set in PDO. -- Edit bug report at http://bugs.php.net/?id=46624&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46624&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46624&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46624&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46624&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46624&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=46624&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46624&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46624&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46624&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46624&r=support Expected behavior: http://bugs.php.net/fix.php?id=46624&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46624&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46624&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46624&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46624&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46624&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46624&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46624&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46624&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46624&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46624&r=mysqlcfg