Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:30098 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75482 invoked by uid 1010); 5 Jun 2007 22:21:01 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75452 invoked from network); 5 Jun 2007 22:21:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2007 22:21:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=mark@cyanox.nl; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mark@cyanox.nl; sender-id=unknown Received-SPF: error (pb1.pair.com: domain cyanox.nl from 77.248.52.200 cause and error) X-PHP-List-Original-Sender: mark@cyanox.nl X-Host-Fingerprint: 77.248.52.200 unknown Received: from [77.248.52.200] ([77.248.52.200:44945] helo=a191140.upc-a.chello.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D6/F2-33808-AC1E5664 for ; Tue, 05 Jun 2007 18:21:00 -0400 Received: from [192.168.0.105] ([::ffff:192.168.0.105]) (AUTH: LOGIN mark, SSL: TLSv1/SSLv3,256bits,AES256-SHA) by a191140.upc-a.chello.nl with esmtp; Wed, 06 Jun 2007 00:21:27 +0200 id 00000000016E8001.000000004665E1E7.00002507 Message-ID: <4665E1BF.5090107@cyanox.nl> Date: Wed, 06 Jun 2007 00:20:47 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.8) Gecko/20061115 Thunderbird/1.5.0.8 Mnenhy/0.7.4.666 MIME-Version: 1.0 To: Antony Dovgal CC: internals@lists.php.net References: <4665D15F.2040501@cyanox.nl> <4665D357.5070509@zend.com> In-Reply-To: <4665D357.5070509@zend.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Recursive classes ... possible bug? From: mark@cyanox.nl ("mark@cyanox.nl") Antony Dovgal wrote: > On 06.06.2007 01:10, mark@cyanox.nl wrote: >> > class class1{ >> public $c2; >> function __construct($c2){ >> $this->c2 = $c2; >> } >> } >> >> class class2{ >> public $c1; >> function setC1($c1){ >> $this->c1 = $c1; >> } >> function test(){ >> echo $this == $this->c1->c2?'equals':'not equals'; // Somehow >> this if statement triggers the error. >> } >> } >> >> >> $tt = new class2(); >> $t = new class1($tt); >> $tt->setC1($t); >> var_dump($t); >> $tt->test(); >> ?> >> >> I get the error: >> >> Fatal error: Nesting level too deep - recursive dependency? in >> /home/cyanox/DEV/test_object_recursion.php on line 15 > > $t->$tt->$t->$tt->$t->$tt->$t->$tt->$t->$tt->$t and so on. > So you get endless recursion when comparing the objects. > >> Although it is obvious that there is a recursion I think this simple >> example should work without error. > > Sure, if you have any proposals/ideas - feel free to share them. > Actually theoretically it should not give an error. I just stumbled upon this odd behavior when doing something very odd which would not work anyway so I can't really think of a situation where the correct behavior would be needed. Anyway the following also gives the error. c2 = $c2; } } class class2{ public $c1; function test(){ $this == $this->c1; // no error. $this == $this; // errors. } } $tt = new class2(); $t = new class1($tt); $tt->c1 = $t; $tt == $t; // no error. //$t == $t; // errors. //$tt == $tt; // errors. $tt->test(); // errors. ?>