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: Open Type: Bug Package: SPL related PHP Version: 5.3.3 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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