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
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.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2021 The PHP Group
All rights reserved.
Last updated: Thu Feb 25 20:01:24 2021 UTC