|  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: 2018-07-12 11:35 UTC
Avg. Score:4.0 ± 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: ajf (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.3 OS: Linux
Private report: No CVE-ID: None
 [2009-04-19 12:51 UTC] c dot r1 at gmx dot de
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.


Add a Patch

Pull Requests

Add a Pull Request


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

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

php > $o = new stdClass;
php > var_export($o);
))php > $o->foo = 123;
php > $o->bar = 456;
php > var_export($o);
   'foo' => 123,
   'bar' => 456,
))php >
 [2015-09-09 13:42 UTC]
-Status: Closed +Status: Re-Opened
 [2015-09-09 13:42 UTC]
@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 <>. 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]
This pull request would fix this, if merged:

Albeit not by adding __set_state, but by using an (object) cast instead.
 [2017-10-24 03:07 UTC]
-Status: Re-Opened +Status: Assigned
 [2018-07-05 19:59 UTC]
-Assigned To: yohgaki +Assigned To: ajf
 [2018-07-12 11:35 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 00:01:26 2019 UTC