ID: 48114
Updated by: [email protected]
Reported By: dcousineau at gmail dot com
-Status: Open
+Status: Closed
Bug Type: SPL related
Operating System: Windows
PHP Version: 5.2.9
New Comment:
Already fixed in PHP_5_3 branch, wont fix (BC :) in PHP_5_2.
Previous Comments:
------------------------------------------------------------------------
[2009-04-29 21:39:02] dcousineau at gmail dot com
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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48114&edit=1