php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
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
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.

Patches

Pull Requests

History

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

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jan 21 23:01:29 2025 UTC