Posted by Mark Evans on 10/20/38 11:29
Hi All
I am coming up against a similar issue as
http://bugs.php.net/bug.php?id=31449
Take the following code for example (from the bug report)
<?php
class Recursive {
private $me;
function __construct() {
$this->me = $this;
}
}
new Recursive() != new Recursive();
?>
A "nesting level too deep" fatal error is thrown... I can kind of see
why this happens...
The bug report is closed as bogus with the following statement
"I don't think it's a bug. You can not compare these objects since they
contain circular references, so comparison process descends to the
endless loop. You may want to use custom method to compare objects -
bit-comparison of objects is generally not the best idea."
the question is how to solve this... I couldnt see any immediate way to
comare 2 objects easily.. Some idea's I came up with...
1. Serialize the 2 objects and then compare the serialized data.
2. Compare the 2 classes using get_class_methods() and get_class_vars()
Is there an easier way? Or has anyone got any better suggestions that I
can use?
Note: the above code is for PHP 5.. I am using PHP 4 and come up against
a similar issue when using mock objects to unit test an observer pattern.
Regards
Mark
[Back to original message]
|