|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43160 FETCH_CLASS
Submitted: 2007-10-31 11:49 UTC Modified: 2007-10-31 12:41 UTC
From: riccardo dot bonciani at cinic dot it Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2.4 OS: Linux Gentoo
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: riccardo dot bonciani at cinic dot it
New email:
PHP Version: OS:


 [2007-10-31 11:49 UTC] riccardo dot bonciani at cinic dot it
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);
$result = $sth->fetchAll(PDO::FETCH_CLASS, 'Test');

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-31 12:41 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 14:01:29 2024 UTC