|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2008-11-19 23:48 UTC] iliaa@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 08:00:01 2025 UTC | 
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.