|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53394 Insufficient docs regarding PDOStatement::fetch(Object) and constructors
Submitted: 2010-11-24 04:13 UTC Modified: 2016-06-29 11:04 UTC
Avg. Score:4.0 ± 0.9
Reproduced:4 of 5 (80.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: public at grik dot net Assigned: cmb (profile)
Status: Closed Package: PDO related
PHP Version: 5.3.3 OS:
Private report: No CVE-ID: None
 [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
 [2016-06-29 10:58 UTC]
-Summary: ARRAY_AS_PROPS flag is ignored when used with PDOStatement::fetchObject +Summary: Insufficient docs regarding PDOStatement::fetch(Object) and constructors -Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: PDO related -Assigned To: +Assigned To: cmb
 [2016-06-29 11:03 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #53394: Insufficient docs regarding PDOStatement::fetch(Object) and constructors
 [2016-06-29 11:04 UTC]
-Status: Verified +Status: Closed
 [2016-06-29 11:04 UTC]
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:07 UTC]
Automatic comment on behalf of cmb
Log: Fix #53394: Insufficient docs regarding PDOStatement::fetch(Object) and constructors
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Aug 16 07:05:45 2022 UTC