<?php
class TestClass {
public $myself;
function __construct () {
$this->myself = $this;
}
}
$TestObj = new TestClass ();
if ( $TestObj->myself == $TestObj ) {
echo "They are same.\n";
}
?>
Gives me a "Fatal error: Nesting level too deep - recursive dependency?"
on line #13: if ( $TestObj->myself == ...)
Could this be a PHP bug or I'm doing something wrong?
FYI:
PHP Version 5.0.2
PHP API 20031224
PHP Extension 20040412
Zend Extension 220040412
Server API Apache 2.0 Handler
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Andi
The same apparent bug exists on my windows xp system, independent of the
sapi, with zend1_compatibility off. It was also in the 5.0.0 release,
so is not an introduction since then.
Greg
Benj Carson
On October 18, 2004 09:39 am, Francisco M. Marzoa Alonso wrote:
> This code:
>
> <?php
>
> class TestClass {
> public $myself;
>
> function __construct () {
> $this->myself = $this;
> }
> }
>
> $TestObj = new TestClass ();
>
> if ( $TestObj->myself == $TestObj ) {
> echo "They are same.\n";
> }
>
> ?>
>
> Gives me a "Fatal error: Nesting level too deep - recursive dependency?"
> on line #13: if ( $TestObj->myself == ...)
>
> Could this be a PHP bug or I'm doing something wrong?
>
> FYI:
>
> PHP Version 5.0.2
> PHP API 20031224
> PHP Extension 20040412
> Zend Extension 220040412
> Server API Apache 2.0 Handler
--
Consider the documentation at
http://www.php.net/manual/en/language.oop5.object-comparison.php : the
documentation is a little vague, but it does say "Two object instances are
equal if they have the same attributes and values, and are instances of the
same class." Thus explaining the recursive loop...
Maybe write a big flashing note in the documentation instead about this
trap?
Jevon
Better, if two values satisfy ===, they are clearly ==. I would imagine
it would not be expensive to simply do a === check before doing the ==
check in the engine?
Greg
Andi
At 05:39 PM 10/18/2004 +0200, Francisco M. Marzoa Alonso wrote:
>This code:
>
><?php
>
>class TestClass {
> public $myself;
>
> function __construct () {
> $this->myself = $this;
> }
>}
>
>$TestObj = new TestClass ();
>
>if ( $TestObj->myself == $TestObj ) {
> echo "They are same.\n";
>}
>
>?>
>
>Gives me a "Fatal error: Nesting level too deep - recursive dependency?"
>on line #13: if ( $TestObj->myself == ...)
>
>Could this be a PHP bug or I'm doing something wrong?
>
>FYI:
>
>PHP Version 5.0.2
>PHP API 20031224
>PHP Extension 20040412
>Zend Extension 220040412
>Server API Apache 2.0 Handler
>
That might actually be a good idea. It would definitely solve some
headaches and be faster.
Does anyone object to me doing this?
Andi
Jevon
At 05:39 PM 10/18/2004 +0200, Francisco M. Marzoa Alonso wrote:
>This code:
>
><?php
>
>class TestClass {
> public $myself;
>
> function __construct () {
> $this->myself = $this;
> }
>}
>
>$TestObj = new TestClass ();
>
>if ( $TestObj->myself == $TestObj ) {
> echo "They are same.\n";
>}
>
>?>
>
>Gives me a "Fatal error: Nesting level too deep - recursive dependency?"
>on line #13: if ( $TestObj->myself == ...)
>
>Could this be a PHP bug or I'm doing something wrong?
>
>FYI:
>
>PHP Version 5.0.2
>PHP API 20031224
>PHP Extension 20040412
>Zend Extension 220040412
>Server API Apache 2.0 Handler
>