|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29361 var_export producing invalid code
Submitted: 2004-07-24 00:14 UTC Modified: 2005-10-17 17:03 UTC
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: Knightking at smempire dot org Assigned: derick (profile)
Status: Closed Package: Class/Object related
PHP Version: 4.3.8 OS: XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: Knightking at smempire dot org
New email:
PHP Version: OS:


 [2004-07-24 00:14 UTC] Knightking at smempire dot org
When var_export is called on an object which has another object as one of its members, it does not produce valid code.

Reproduce code:
$a->b = 1;
eval(var_export($a, 1) . ';');

Actual result:
Fatal error: Cannot redeclare class stdclass in test.php(3) : eval()'d code on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-29 09:39 UTC] degusta at yahoo dot com
A similar, perhaps identical problem also occurs with arrays that contain objects. In that case the code produced by var_export causes an unexpected T_CLASS parse error.

Here's the code produced by var_export for the array with an object:
array (
  0 => 
  class myclass {
    var $myProperty = 'myValue';
 [2004-08-02 12:57 UTC]
THere is no way how this can be fixed; if you can think of something how this should work, please provide a patch.
 [2005-10-17 10:55 UTC]
I found a way myself now, assigning.
 [2005-10-17 17:03 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed for PHP 5.1.0 and 6.0.0 (and higher).
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 16:01:30 2024 UTC