#27707 [Opn->WFx]: comparing (recursive) referenced objects fails

From: Date: Mon, 29 Mar 2004 01:22:15 +0000
Subject: #27707 [Opn->WFx]: comparing (recursive) referenced objects fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56993@lists.php.net to get a copy of this message
ID: 27707 Updated by: iliaa@php.net Reported By: jesse at mactechs dot com -Status: Open +Status: Wont fix Bug Type: Class/Object related Operating System: Irrelevant PHP Version: 4.3.4 New Comment: This is fixed in PHP 5.0, it won't however be fixed for PHP 4. Previous Comments: ------------------------------------------------------------------------ [2004-03-25 19:39:14] 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-25 19:34:05] 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 " ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27707&edit=1

« previous php.bugs (#56993) next »