Bug->Doc #67918 [Opn->Ver]: var_export does not export a parsable string representation of stdClass objects
| From: | cmb@php.net | Date: | Wed, 09 Sep 2015 13:44:22 +0000 |
| Subject: | Bug->Doc #67918 [Opn->Ver]: var_export does not export a parsable string representation of stdClass objects | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12743@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67918&edit=1
ID: 67918
Updated by: cmb@php.net
Reported by: php-bugs-2014-08 at dotancohen dot com
Summary: var_export does not export a parsable string
representation of stdClass objects
-Status: Open
+Status: Verified
-Type: Bug
+Type: Documentation Problem
Package: Class/Object related
Operating System: Linux melancholy 3.13.0-34-gener
PHP Version: 5.5.16
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Indeed, bug #48016 has been closed erroneously, so I re-opened it.
Instead of marking this ticket as duplicate, I'm switching to
documentation problem, because the current behavior has to be
documented anyway.
Previous Comments:
------------------------------------------------------------------------
[2014-08-27 17:46:47] php-bugs-2014-08 at dotancohen dot com
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 this bug report at https://bugs.php.net/bug.php?id=67918&edit=1