# Nesting level too deep - recursive dependency?

- Thread: https://externals.io/message/13373
- Original archive: https://news-web.php.net/php.internals/13373
- Started by Francisco M. Marzoa Alonso on 2004-10-18T15:39:09+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #13373 — Francisco M. Marzoa Alonso — 2004-10-18T15:39:09+00:00

URL: https://externals.io/message/13373#13373

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

---

## #13378 — Andi Gutmans — 2004-10-19T01:18:37+00:00

URL: https://externals.io/message/13373#13378 · In reply to: #13373

Are you using zend.zend1_compatibility_mode on?

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

---

## #13383 — Greg Beaver — 2004-10-19T03:21:04+00:00

URL: https://externals.io/message/13373#13383 · In reply to: #13378

Andi Gutmans wrote:
> Are you using zend.zend1_compatibility_mode on?
> 
> 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

---

## #13384 — Benj Carson — 2004-10-19T04:51:00+00:00

URL: https://externals.io/message/13373#13384 · In reply to: #13373

If you use '===' it works as expected.  I don't know if the fact that '==' 
doesn't work is a bug or not, however.


Benj Carson



> 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

---

## #13385 — Jevon Wright — 2004-10-19T06:35:48+00:00

URL: https://externals.io/message/13373#13385 · In reply to: #13384

I first stumbled upon this problem in one of the RCs for PHP 5, but at the
time I thought I was at fault...

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

----- Original Message ----- 
From: "Benj Carson" <benjcarson@digitaljunkies.ca>
To: <internals@lists.php.net>
Sent: Tuesday, October 19, 2004 5:51 PM
Subject: Re: [PHP-DEV] Nesting level too deep - recursive dependency?


> If you use '===' it works as expected.  I don't know if the fact that '=='
> doesn't work is a bug or not, however.
>
>
> Benj Carson
>
>
> 
> > […]

---

## #13391 — Greg Beaver — 2004-10-19T14:10:56+00:00

URL: https://externals.io/message/13373#13391 · In reply to: #13385

Jevon Wright wrote:
> I first stumbled upon this problem in one of the RCs for PHP 5, but at the
> time I thought I was at fault...
> 
> 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?

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

---

## #13394 — Andi Gutmans — 2004-10-19T17:44:56+00:00

URL: https://externals.io/message/13373#13394 · In reply to: #13373

The reason is that == compares the elements as opposed to === which 
compares the object handles.
We get infinite recursion comparing these two because the object points at 
itself.
I'm not sure if there's a good way of solving that.
Do you really want == ordoes === do the job for you?

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

---

## #13418 — Andi Gutmans — 2004-10-20T17:57:55+00:00

URL: https://externals.io/message/13373#13418 · In reply to: #13373

Fixed in CVS.

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
