php.net |  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
Votes:2
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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Knightking at smempire dot org
New email:
PHP Version: OS:

 

 [2004-07-24 00:14 UTC] Knightking at smempire dot org
Description:
------------
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

Patches

Pull Requests

History

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] derick@php.net
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] derick@php.net
I found a way myself now, assigning.
 [2005-10-17 17:03 UTC] derick@php.net
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
http://snaps.php.net/.
 
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: Thu Nov 21 15:01:30 2024 UTC