Comparison of class with recursive references causes fatal error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux