Req #48016 [ReO->Asn]: stdClass::__setState is not defined although var_export() uses it

From: Date: Tue, 24 Oct 2017 03:07:02 +0000
Subject: Req #48016 [ReO->Asn]: stdClass::__setState is not defined although var_export() uses it
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211890@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: kalle@php.net Reported by: c dot r1 at gmx dot de Summary: stdClass::__setState is not defined although var_export() uses it -Status: Re-Opened +Status: Assigned 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 Previous Comments: ------------------------------------------------------------------------ [2017-03-14 17:30:25] 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. ------------------------------------------------------------------------ [2015-09-09 13:44:20] cmb@php.net Related To: Bug #67918 ------------------------------------------------------------------------ [2015-09-09 13:42:40] 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(...) ------------------------------------------------------------------------ [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

« previous php.bugs (#211890) next »