#38866 [Bgs->Opn]: Nesting level too deep Error when Object Contains Self Reference

From: Date: Mon, 18 Sep 2006 15:21:15 +0000
Subject: #38866 [Bgs->Opn]: Nesting level too deep Error when Object Contains Self Reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-102336@lists.php.net to get a copy of this message
ID: 38866 User updated by: adam at sccode dot com Reported By: adam at sccode dot com -Status: Bogus +Status: Open Bug Type: Class/Object related Operating System: Windows 2000 PHP Version: 5CVS-2006-09-18 (snap) New Comment: Apologies ... I posted the wrong reproduce code: private function __construct() { $this->me = $this; } Should read: private function __construct() { self::$instance = $this; } In previous versions of PHP this has produced no error. There are sometimes occasions where checking if two varaibles reference the same object instance is necessaary - I don't think a static property should break this. Previous Comments: ------------------------------------------------------------------------ [2006-09-18 15:11:04] tony2001@php.net With $this->attr = $this you get recursive references, so the error message is expected. ------------------------------------------------------------------------ [2006-09-18 14:37:19] adam at sccode dot com Description: ------------ Attempting to compare two variables containing a reference to an object instance which in turn contains a property static or otherwise, referring back to itself produces a "Nesting level too deep" fatal error. One example where a self references may be necessary is a singleton: in PHP 5.1.6 the reproduce code works as expected. A feature, or a bug? Reproduce code: --------------- $obj = Singleton::instance(); $obj2 = $obj; var_dump($obj != $obj2); class Singleton { private static $instance; private function __construct() { $this->me = $this; } public static function instance() { if (! self::$instance) { self::$instance = new Singleton; } return self::$instance; } } Expected result: ---------------- bool(false) Actual result: -------------- Fatal error: Nesting level too deep - recursive dependency? in crash-test.php on line 5 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38866&edit=1

« previous php.bugs (#102336) next »