Edit report at http://bugs.php.net/bug.php?id=53394&edit=1
ID: 53394
Comment by: public at grik dot net
Reported by: public at grik dot net
Summary: ARRAY_AS_PROPS flag is ignored when used with
PDOStatement::fetchObject
Status: Bogus
Type: Bug
Package: SPL related
PHP Version: 5.3.3
Assigned To: felipe
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2010-11-24 22:16:34] [email protected]
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']);
Thanks.
------------------------------------------------------------------------
[2010-11-24 15:27:19] [email protected]
Felipe, could you check this out plz?
------------------------------------------------------------------------
[2010-11-24 15:25:58] [email protected]
Please try using this snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2010-11-24 13:54:20] 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 13:46:58] public at grik dot net
I was hinted that PDO sets the fields before calling a constructor.
It makes everything clear.
parent::__construct($array,ArrayObject::ARRAY_AS_PROPS);
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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/bug.php?id=53394
--
Edit this bug report at http://bugs.php.net/bug.php?id=53394&edit=1