Skip to content

Commit

Permalink
Fix errors with recursion in debug()
Browse files Browse the repository at this point in the history
Fixes #3102
  • Loading branch information
markstory committed Aug 9, 2012
1 parent 476bd80 commit dca050f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/Cake/Test/Case/Utility/DebuggerTest.php
Expand Up @@ -477,6 +477,16 @@ public function testNoDbCredentials() {
$this->assertEquals($expected, $output);
}

/**
* Test that exportVar() doesn't loop through recursive structures.
*
* @return void
*/
public function testExportVarRecursion() {
$output = Debugger::exportVar($GLOBALS);
$this->assertContains("'GLOBALS' => [recursion]", $output);
}

/**
* test trace exclude
*
Expand Down
7 changes: 6 additions & 1 deletion lib/Cake/Utility/Debugger.php
Expand Up @@ -542,9 +542,14 @@ protected static function _array(array $var, $depth, $indent) {

if ($depth >= 0) {
foreach ($var as $key => $val) {
if ($val !== $var) {
$val = self::_export($val, $depth, $indent);
} else {
$val = '[recursion]';
}
$vars[] = $break . self::exportVar($key) .
' => ' .
self::_export($val, $depth, $indent);
$val;
}
} else {
$vars[] = $break . '[maximum depth reached]';
Expand Down

0 comments on commit dca050f

Please sign in to comment.