php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48114 ArrayObject::ARRAY_AS_PROPS setting does not serialize
Submitted: 2009-04-29 21:39 UTC Modified: 2009-04-30 08:33 UTC
From: dcousineau at gmail dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 5.2.9 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dcousineau at gmail dot com
New email:
PHP Version: OS:

 

 [2009-04-29 21:39 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-30 08:33 UTC] jani@php.net
Already fixed in PHP_5_3 branch, wont fix (BC :) in PHP_5_2.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC