|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27707 comparing (recursive) referenced objects fails
Submitted: 2004-03-25 19:34 UTC Modified: 2004-03-28 20:22 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jesse at mactechs dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 4.3.4 OS: Irrelevant
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.
Block user comment
Status: Assign to:
Bug Type:
From: jesse at mactechs dot com
New email:
PHP Version: OS:


 [2004-03-25 19:34 UTC] jesse at mactechs dot com
Recursive object reference comparisons fail in PHP4.x.

Alternative to my "exptected result" below, I would 
settle for one of a couple of things.  One would be a 
boolean comparison function that returns true if two 
references point to the same data, or another could be 
simply a boolean function that returns true if two 
objects are the same (with recursing to all the values).

I'm aware the Zend Engine 2/PHP5 identity operator works 
in the fashion I'd like now, but I'd still consider this 
a bug for Zend Engine/PHP4.

Reproduce code:
// key failing element here is B::is_ref

class A {
  var $a_ref;
  function set_ref (&$obj) {
    $this->a_ref =& $obj; } }
class B {
  var $b_ref;
  function set_ref (&$obj) {
    $this->b_ref =& $obj; }
  function is_ref (&$obj) {
    if ($obj === $this->b_ref)
      return true; } }

$a = new A; $b = new B;
$a->set_ref ($b); $b->set_ref ($a);

var_dump ($b->is_ref ($a));

Expected result:
I would expect that "if ($obj === $this->b_ref)" would 
return true if they (the two object references being 
compared) referenced the same object, and 
false if they didnt.  Please see my description, as 

Actual result:
Fatal error: Nesting level too deep - recursive 
dependency? in /path-to/test.php on line 12


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-25 19:39 UTC] jesse at mactechs dot com
Correction: last words of last sentance of second 
paragraph of description should read: "(WITHOUT 
recursing to all the values)".
 [2004-03-28 20:22 UTC]
This is fixed in PHP 5.0, it won't however be fixed for PHP 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jan 27 02:05:53 2023 UTC