|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62200 ArrayObject should implement __set_state()
Submitted: 2012-05-31 23:50 UTC Modified: 2016-06-29 17:04 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: bkam at citiesunlimited dot com Assigned:
Status: Closed Package: SPL related
PHP Version: 5.4.3 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: bkam at citiesunlimited dot com
New email:
PHP Version: OS:


 [2012-05-31 23:50 UTC] bkam at citiesunlimited dot com
Pretty simple, var_export of SPL traversibles shows Class::__set_state([]) but 
actually calling that function throws an undefined method error.

This is specifically true for ArrayObject, but generally true for all the 
traversibles with inaccessible internal structures.

Test script:
$a = new ArrayObject();
$a['key'] = 'value';

// returns
//"ArrayObject::__set_state(array( 'key' => 'value', ))"

$ao = ArrayObject::__set_state(['thing' => 'value']);
//"Fatal error: Call to undefined method ArrayObject::__set_state()"

Expected result:
"ArrayObject::__set_state(array( 'key' => 'value', ))"


Actual result:
"Fatal error: Call to undefined method ArrayObject::__set_state()"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-04 23:54 UTC]
-Type: Bug +Type: Documentation Problem
 [2012-06-04 23:54 UTC]
This should be cleared in the documentation. The code returned is valid PHP code, while it won't necessarily run successful.

var_export() assumes a __set_state() exists, but there are cases where it doesn't and there are cases where for different reasons it never can in a sufficient way. Especially for internal classes where we can't export the full state.
 [2012-06-05 00:11 UTC] bkam at citiesunlimited dot com
For this class, that's not an acceptable position to take.  Consider that I can 

class AdaptorArrayObject extends \ArrayObject {
	public static function __set_state(Array $data) {

//some data that's structured appropriately for ArrayObject state
$oldArrayObjectData = $existingArrayObject->getArrayCopy();

$newArrayObject = AdaptorArrayObject::__set_state($oldArrayObjectData);

You already wrote the functions necessary to implement __set_state()

Why is it on ME to subclass just to call the functions to make this work?  
Functions are written, call them internally and expose __set_state. Easy peasy.

The other SPL data structures are indeed much more complex internally (object 
keys, kv meta data, and value linking), so it makes sense not to offer external 
functions like exchangeArray or getArrayCopy.  But ArrayObject is supposed to be 
much closer to [] is it not? just wrapped in object reference semantics and SPL 
API goodies?

Please reconsider for ArrayObject.
 [2016-06-29 17:03 UTC]
Automatic comment from SVN on behalf of cmb
Log: Fix #62200: __set_state() not implemented
 [2016-06-29 17:04 UTC]
-Summary: __set_state() not implemented +Summary: ArrayObject should implement __set_state() -Type: Documentation Problem +Type: Feature/Change Request
 [2016-06-29 17:04 UTC]
I have fixed the documentation, and change this ticket to feature
 [2020-02-07 06:07 UTC]
Automatic comment on behalf of cmb
Log: Fix #62200: __set_state() not implemented
 [2020-02-07 06:07 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Dec 03 07:03:34 2021 UTC