Req #48016 [Csd->ReO]: stdClass::__setState is not defined although var_export() uses it
| From: | cmb@php.net | Date: | Wed, 09 Sep 2015 13:42:41 +0000 |
| Subject: | Req #48016 [Csd->ReO]: stdClass::__setState is not defined although var_export() uses it | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195907@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48016&edit=1
ID: 48016
Updated by: cmb@php.net
Reported by: c dot r1 at gmx dot de
Summary: stdClass::__setState is not defined although
var_export() uses it
-Status: Closed
+Status: Re-Opened
Type: Feature/Change Request
Package: Class/Object related
Operating System: Linux
PHP Version: 5.3
Assigned To: yohgaki
Block user comment: N
Private report: N
New Comment:
@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(...)
Previous Comments:
------------------------------------------------------------------------
[2013-08-06 06:20:55] 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 >
------------------------------------------------------------------------
[2009-04-19 12:51:05] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=48016&edit=1