[PHP-BUG] Bug #51445 [NEW]: var_dump() invalid/slow *RECURSION* detection

[email protected] ("php at bfanger dot nl") Wed, 31 Mar 2010 14:09:51 +0200 (CEST)
Newsgroups php.bugs
Message-ID <[email protected]>
From:             
Operating system: (Arch)Linux
PHP version:      5.3.2
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:var_dump() invalid/slow *RECURSION* detection

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*
        )

)


-- 
Edit bug report at http://bugs.php.net/bug.php?id=51445&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=51445&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=51445&r=trysnapshot53
Try a snapshot (PHP 6.0):            http://bugs.php.net/fix.php?id=51445&r=trysnapshot60
Fixed in SVN:                        http://bugs.php.net/fix.php?id=51445&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51445&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=51445&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=51445&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=51445&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=51445&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=51445&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=51445&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=51445&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=51445&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=51445&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51445&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51445&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=51445&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=51445&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=51445&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=51445&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=51445&r=mysqlcfg