|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53394 ARRAY_AS_PROPS flag is ignored when used with PDOStatement::fetchObject
Submitted: 2010-11-24 04:13 UTC Modified: 2011-11-16 14:24 UTC
Avg. Score:3.8 ± 0.8
Reproduced:3 of 4 (75.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: public at grik dot net Assigned:
Status: Open Package: Documentation problem
PHP Version: 5.3.3 OS:
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-11-24 04:13 UTC] public at grik dot net
If the object is created and filled by PDOStatement::fetchObject, the ArrayObject::ARRAY_AS_PROPS is ignored.

Seems like PDO sets the fields values directly around ArrayObject magic setters, and breaks the ArrayObject native behaviour.

Test script:
class ArraySlice extends ArrayObject{
    function __construct(array $array=array()){
$PDO = new PDO($dsn, $user, $password);
$a = $PDO->query('select id from links')->fetchObject('ArraySlice');
echo $a->id; //works
echo $a['id'];//Notice occured ... Undefined index:  id

Expected result:
value of the id field

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-24 13:46 UTC] public at grik dot net
I was hinted that PDO sets the fields before calling a constructor.
It makes everything clear.

is called after setting object fields, and they don't get processed by ArrayObject::offsetSet.
ArrayObject::Š¾ffsetGet after changing mode to ARRAY_AS_PROPS doesn't see the fields set by the PDO hack.

Š¾ffsetGet can process existing fields after changing the mode, I suppose.
 [2010-11-24 13:54 UTC] crocodile2u at gmail dot com
Or possibly it would be better to change the PDO's behaviour? It seems very 
strange and unnatural that constructor is called after the properties are set. It 
only makes developers write unobvious code for the only purpose of workaround for 
this PDO's feature (personally, I would consider it a bug).
 [2010-11-24 15:25 UTC]
-Status: Open +Status: Feedback
 [2010-11-24 15:25 UTC]
Please try using this snapshot:
For Windows:

 [2010-11-24 15:27 UTC]
-Status: Feedback +Status: Assigned -Assigned To: +Assigned To: felipe
 [2010-11-24 15:27 UTC]
Felipe, could you check this out plz?
 [2010-11-24 22:16 UTC]
-Status: Assigned +Status: Bogus
 [2010-11-24 22:16 UTC]
Hi, there was a discussion about this, see bug #49521

You could do something like this:

$a = $PDO->query('select id from links');
$a->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE, 'ArraySlice');
$a = $a->fetch();
var_dump($a->id, $a['id']);

 [2010-11-24 23:32 UTC] public at grik dot net
It's not bogus. It is a documentation issue at least.
I guess, it needs to be described somewhere beyond the bugtracker.

all I see in docs is:
PDO::FETCH_PROPS_LATE ( integer ) 
Available since PHP 5.2.0
 [2010-11-24 23:49 UTC]
-Status: Bogus +Status: To be documented -Assigned To: felipe +Assigned To:
 [2010-11-24 23:49 UTC]
Right, it needs be documented.
 [2011-11-16 14:24 UTC]
-Package: SPL related +Package: Documentation problem
PHP Copyright © 2001-2016 The PHP Group
All rights reserved.
Last updated: Wed May 25 03:01:41 2016 UTC