#38866 [Opn->Bgs]: Nesting level too deep Error when Object Contains Self Reference
| From: | johannes@php.net | Date: | Mon, 18 Sep 2006 16:00:10 +0000 |
| Subject: | #38866 [Opn->Bgs]: Nesting level too deep Error when Object Contains Self Reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-102344@lists.php.net to get a copy of this message | ||
ID: 38866
Updated by: johannes@php.net
Reported By: adam at sccode dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Windows 2000
PHP Version: 5CVS-2006-09-18 (snap)
New Comment:
No PHP problem -> bogus
Previous Comments:
------------------------------------------------------------------------
[2006-09-18 15:56:01] adam at sccode dot com
You're right!! I am having a bad day - I was changing the wrong file
all along. I'm very sorry to have wasted your time.
------------------------------------------------------------------------
[2006-09-18 15:35:45] tony2001@php.net
After this change I get only bool(false).
What is the problem?
------------------------------------------------------------------------
[2006-09-18 15:21:14] adam at sccode dot com
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.
------------------------------------------------------------------------
[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