Edit report at http://bugs.php.net/bug.php?id=53394&edit=1
ID: 53394 Updated by: tony2...@php.net Reported by: public at grik dot net Summary: ARRAY_AS_PROPS flag is ignored when used with PDOStatement::fetchObject -Status: Open +Status: Feedback Type: Bug Package: SPL related PHP Version: 5.3.3 Block user comment: N Private report: N New Comment: Please try using this snapshot: http://snaps.php.net/php5.3-latest.tar.gz For Windows: http://windows.php.net/snapshots/ Previous Comments: ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ [2010-11-24 04:13:05] public at grik dot net Description: ------------ 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()){ parent::__construct($array,ArrayObject::ARRAY_AS_PROPS); } } $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: -------------- Notice ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53394&edit=1