php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16074 CVS function var_export() can't handle recursive arrays
Submitted: 2002-03-14 10:39 UTC Modified: 2002-03-14 10:44 UTC
From: ahristov at icygen dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.0CVS-2002-03-14 OS: RH 7.1
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ahristov at icygen dot com
New email:
PHP Version: OS:

 

 [2002-03-14 10:39 UTC] ahristov at icygen dot com
 The problem is similar to var_dump(). var_dump() is fixed by Yasuo today but another one raised (see Bug#16065)
var_export() has to handle recursive dependencies better and the fatal error is not an option.
Here is the script:
<?php 
$a=array(); 
$a[]=&$a; 
var_export($a);
?>
and the ouput:
bash-2.04$ ../php export.php 
X-Powered-By: PHP/4.3.0-dev
Content-type: text/html

array (
  0 => 
  array (
    0 => 
    array (
      0 => 
      array (
PHP Fatal error:  Nesting level too deep - recursive dependency? in /usr/samba/users/andy/412dev/php4-200203140300/te/export.php on line 4
<br />
<b>Fatal error</b>:  Nesting level too deep - recursive dependency? in <b>/usr/samba/users/andy/412dev/php4-200203140300/te/export.php</b> on line <b>4</b><br />

 Possible fix is another parameter(string) with var_export()-ed variable name - this will fix if the array has element which is reference to the array but will not handle this :
<?php
$a=array(1,2); 
$a[]=&$a; 
$b=array(&$a,3,4);
var_export($a);
?>
that crashes with output :
array (
  0 => 1,
  1 => 2,
  2 => 
  array (
    0 => 1,
    1 => 2,
    2 => 
    array (
      0 => 1,
      1 => 2,
      2 => 
      array (
        0 => 1,
        1 => 2,
        2 => 
        array (
PHP Fatal error:  Nesting level too deep - recursive dependency? in /usr/samba/users/andy/412dev/php4-200203140300/te/export.php on line 6
<br />
<b>Fatal error</b>:  Nesting level too deep - recursive dependency? in <b>/usr/samba/users/andy/412dev/php4-200203140300/te/export.php</b> on line <b>6</b><br />

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-14 10:44 UTC] derick@php.net
var_export() isn't meant for recursive structures, fixing this makes no sense.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 18:02:40 2024 UTC