|
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-2026 The PHP GroupAll rights reserved. |
Last updated: Sun Jan 04 02:00:01 2026 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.