Bug #67918 [NEW]: var_export does not export a parsable string representation of stdClass objects
| From: | php-bugs-2014-08 at dotancohen dot com | Date: | Wed, 27 Aug 2014 17:46:48 +0000 |
| Subject: | Bug #67918 [NEW]: var_export does not export a parsable string representation of stdClass objects | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187301@lists.php.net to get a copy of this message | ||
From: php-bugs-2014-08 at dotancohen dot com
Operating system: Linux melancholy 3.13.0-34-gener
PHP version: 5.5.16
Package: Class/Object related
Bug Type: Bug
Bug description:var_export does not export a parsable string representation of stdClass objects
Description:
------------
Though var_export() is designed to "outputs or return a parsable string
representation of a variable", the output of stdClass objects is not "a
parsable string". Witness:
php > $foo = new stdClass();
php > var_export($foo);
stdClass::__set_state(array(
))
php > $bar = stdClass::__set_state(array());
PHP Fatal error: Call to undefined method stdClass::__set_state() in
php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. {main}() php shell code:0
Relevant quote from the fine manual:
> var_export() gets structured information about the given variable. It
> is similar to var_dump() with one exception: the returned
representation
> is valid PHP code.
Note that the output presented above is not valid PHP code.
It seems that bug #48016 attacks the same issue from the other side
(stdClass::__setState is not defined although var_export uses it),
however that bug was closed prematurely, as the test case used to
justify the close does not demonstrate that the issue is resolved.
Test script:
---------------
$ php -a
php > $foo = new stdClass();
php > var_export($foo);
stdClass::__set_state(array(
))
php > $bar = stdClass::__set_state(array());
PHP Fatal error: Call to undefined method stdClass::__set_state() in
php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. {main}() php shell code:0
--
Edit bug report at https://bugs.php.net/bug.php?id=67918&edit=1
--