|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-04-30 08:33 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Feb 17 13:00:01 2026 UTC |
Description: ------------ By default (for some reason) SPL's ArrayObject does not allow accessing members like object properties. In order to enable this behavior you must use the **UNDOCUMENTED** technique of `$arrayobject = new ArrayObject($array, ArrayObject::ARRAY_AS_PROPS);`. However this setting is not saved during serialization, so when unserializing the ArrayObject it reverts to it's default behavior (throwing errors when trying to perform a `$arrayobject->key;`). I believe given that since this is a mapping of an array to an object (and not arrayaccess), ARRAY_AS_PROPS should be default behavior. However, if one is paranoid about BC breaks, at least update ArrayObject to store the ARRAY_AS_PROPS flag to support serialization. Reproduce code: --------------- <?php $arrayobject = new ArrayObject(array('key'=>'value'), ArrayObject::ARRAY_AS_PROPS); echo $arrayobject->key; $arrayobject = serialize($arrayobject); $arrayobject = unserialize($arrayobject); echo $arrayobject->key; Expected result: ---------------- 'value' 'value' Actual result: -------------- An error is raise on the last line trying to access a nonexistant property.