|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-10-31 12:41 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 15:00:01 2025 UTC |
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.