PHP 4.0 Bug #6896 Updated: A class cannot have a reference to it's instance
| From: | waldschrott@php.net | Date: | Wed, 06 Dec 2000 21:56:18 +0000 |
| Subject: | PHP 4.0 Bug #6896 Updated: A class cannot have a reference to it's instance | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-40262@lists.php.net to get a copy of this message | ||
ID: 6896
Updated by: waldschrott
Reported By: davefox@angryrobot.com
Status: Closed
Bug Type: Class/Object related
Assigned To:
Comments:
fixed in cvs, it should work...
Previous Comments:
---------------------------------------------------------------------------
[2000-10-05 17:51:50] stas@php.net
Circular references are not currently supported
---------------------------------------------------------------------------
[2000-09-27 01:52:35] davefox@angryrobot.com
This bug appeared when I installed php4.0.2, I had
php4.0.1RC before.
I'm trying to add a reference to Parent to each Child as its created. It seems like the
Parent->baseObj property cannot be a reference to $this, its instance.
An example of the code that caused the problem:
<?
class Parent {
function Parent(){
$this->baseObj = &$this;
}
function insert($name){
/* This will work
if(get_class($this) == 'parent'){
$this->test[$name] = new Child(); $this->test[$name]->baseObj = &$this;
}
else {
$this->baseObj->test[$name] = new Child();
$this->baseObj->test[$name]->baseObj = &$this->baseObj;
}
/*
/* This will not - says error: call to member function on non-object */
$this->baseObj->test[$name] = new Child(); $this->baseObj->test[$name]->baseObj
= &$this->baseObj;
}
}
class Child extends Parent{
function Child(){
$this->whatever = 'sometext';
}
function showMe(){
echo "I exist";
}
}
$obj = new Parent();
$obj->insert('foo');
$obj->test['foo']->insert('bar');
$obj->test['bar']->insert('blah');
$obj->test['foo']->showMe();
$obj->test['bar']->showMe();
$obj->test['blah']->showMe();
?>
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=6896