php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68464 Undetected recursion when using __debugInfo()
Submitted: 2014-11-20 19:15 UTC Modified: 2016-07-14 11:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: dev at pp3345 dot net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6.3 OS: Debian 7 Wheezy
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: dev at pp3345 dot net
New email:
PHP Version: OS:

 

 [2014-11-20 19:15 UTC] dev at pp3345 dot net
Description:
------------
Hello,

it seems that the recursion detection for var_dump() doesn't work when using objects with __debugInfo(), which causes an infinite loop. The problem seems to be located in ext/standard/var.c:129:

		myht = Z_OBJDEBUG_PP(struc, is_temp);
		if (myht && ++myht->nApplyCount > 1) {
			PUTS("*RECURSION*\n");
			--myht->nApplyCount;
			return;
		}

Z_OBJDEBUG_PP() gives either a hashtable containing all properties of an object or, if __debugInfo() is available, the hashtable returned by that method. Since this hashtable is recreated on every call to __debugInfo(), changing it's nApplyCount value won't help for detecting object recursion. Probably the objprop hashtable should always be used for recursion detection.

Test script:
---------------
<?php

class A {
        public $x = null;

        public function __debugInfo() {
                return ["x" => $this->x];
        }
}

class B {
        public $y = null;

        public function __debugInfo() {
                return ["y" => $this->y];
        }
}

$a = new A;
$a->x = new B;
$a->x->y = $a;

var_dump($a);

Expected result:
----------------
object(A)#1 (1) {
  ["x"]=>
  object(B)#2 (1) {
    ["y"]=>
    *RECURSION*
  }
}

Actual result:
--------------
Infinite loop

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-14 11:00 UTC] dmitry@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: dmitry
 [2016-07-14 11:00 UTC] dmitry@php.net
The bug has been fixed in PHP-7.0.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 07:00:01 2026 UTC