php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jesse at mactechs dot com
New email:
PHP Version: OS:

 

 [2004-03-25 19:34 UTC] jesse at mactechs dot com
Description:
------------
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 
well.

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

Patches

Pull Requests

History

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] iliaa@php.net
This is fixed in PHP 5.0, it won't however be fixed for PHP 
4. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 05:01:28 2025 UTC