php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48016 stdClass::__setState is not defined although var_export() uses it
Submitted: 2009-04-19 12:51 UTC Modified: 2017-10-24 03:07 UTC
Votes:8
Avg. Score:4.1 ± 0.9
Reproduced:8 of 8 (100.0%)
Same Version:4 (50.0%)
Same OS:4 (50.0%)
From: c dot r1 at gmx dot de Assigned: yohgaki (profile)
Status: Assigned Package: Class/Object related
PHP Version: 5.3 OS: Linux
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: c dot r1 at gmx dot de
New email:
PHP Version: OS:

 

 [2009-04-19 12:51 UTC] c dot r1 at gmx dot de
Description:
------------
var_export() for an object which is just used for storing properties and is of stdClass produces invalid code as stdClass::__setState is not implemented, for no appearant reason. It would be nice to have an implementation of this in 5.3.0, and, if possible, a workaround for earlier versions of php.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-08 20:31 UTC] jani@php.net
-Package: Feature/Change Request +Package: Class/Object related -PHP Version: 5.2.9 +PHP Version: 5.3
 [2013-08-06 06:20 UTC] yohgaki@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: yohgaki
 [2013-08-06 06:20 UTC] yohgaki@php.net
It seems issue is fixed.

[yohgaki@dev PHP-5.4]$ ./php-bin -a
Interactive shell

php > $o = new stdClass;
php > var_export($o);
stdClass::__set_state(array(
))php > $o->foo = 123;
php > $o->bar = 456;
php > var_export($o);
stdClass::__set_state(array(
   'foo' => 123,
   'bar' => 456,
))php >
 [2015-09-09 13:42 UTC] cmb@php.net
-Status: Closed +Status: Re-Opened
 [2015-09-09 13:42 UTC] cmb@php.net
@yohgaki: The issue is not that var_export() fails, but rather
that the exported representation can't be eval'd (i.e. imported
again), see <https://3v4l.org/XSPRH>. So either StdClass should
implement __set_state() or var_export() should export something
like the following for StdClass instances:

  (object) array(...)
 [2017-03-14 17:30 UTC] ajf@php.net
This pull request would fix this, if merged: https://github.com/php/php-src/pull/2420

Albeit not by adding __set_state, but by using an (object) cast instead.
 [2017-10-24 03:07 UTC] kalle@php.net
-Status: Re-Opened +Status: Assigned
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC