Req #48016 [Com]: stdClass::__setState is not defined although var_export() uses it

From: Date: Tue, 06 Aug 2019 23:53:49 +0000
Subject: Req #48016 [Com]: stdClass::__setState is not defined although var_export() uses it
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222114@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 Comment by: roy-orbison at devo dot net dot au Reported by: c dot r1 at gmx dot de Summary: stdClass::__setState is not defined although var_export() uses it Status: Closed Type: Feature/Change Request Package: Class/Object related Operating System: Linux PHP Version: 5.3 Assigned To: ajf Block user comment: N Private report: N New Comment: Because the fix does not make data exported the old way parsable (I assume for consistent behaviour), you can repair it by replacing "stdClass::__set_state" with "(object)", sans quotes. Previous Comments: ------------------------------------------------------------------------ [2018-07-12 11:35:08] cmb@php.net This has been fixed: <http://git.php.net/?p=php-src.git;a=commit;h=e4e9cd835550990a6b8df7c61d59b6cc0da9b5b2>. ------------------------------------------------------------------------ [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 > ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=48016 -- Edit this bug report at https://bugs.php.net/bug.php?id=48016&edit=1

« previous php.bugs (#222114) next »