php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51445 var_dump() invalid/slow *RECURSION* detection
Submitted: 2010-03-31 14:09 UTC Modified: 2010-04-03 00:04 UTC
From: php at bfanger dot nl Assigned: felipe
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.2 OS: (Arch)Linux
Private report: No CVE-ID:
 [2010-03-31 14:09 UTC] php at bfanger dot nl
Description:
------------
The var_dump() function doesn't detect recursion properly(aka the first time).
The code sample will show that var_dump() will print de "second" twice instead 
of once like in print_r().

This goes terribly wrong with large var_dumps with multiple recursion.
print_r() needed 5MiB memory for my dump. and var_dump() needed more than the  
ini_set("memory_limit", "1G") I applied. 

Code for generating a big dump.
class IndexController extends Zend_Controller_Action {
    public function indexAction() {
        var_dump($this->_helpers);
    }
}



Test script:
---------------
<?php
$array = array(
	'first' => array(),
);
$array['first']['second'] = &$array['first'];
echo "<pre>\n";
var_dump($array);
echo "\n\n";
print_r($array);
echo "<pre>\n";
?>


Expected result:
----------------
<pre>
array(1) {
  ["first"]=>
  &array(1) {
    ["second"]=>
    *RECURSION*
  }
}


Array
(
    [first] => Array
        (
            [second] => Array
 *RECURSION*
        )

)

Actual result:
--------------
<pre>
array(1) {
  ["first"]=>
  &array(1) {
    ["second"]=>
    &array(1) {
      ["second"]=>
      *RECURSION*
    }
  }
}


Array
(
    [first] => Array
        (
            [second] => Array
 *RECURSION*
        )

)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-02 23:44 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=297375
Log: - Fixed bug #51445 (var_dump() invalid/slow *RECURSION* detection)
 [2010-04-03 00:04 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2010-04-03 00:04 UTC] felipe@php.net
This bug has been fixed in SVN.

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.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 06:02:27 2014 UTC