note 23465 deleted from language.oop by vincent
| From: | vincent@php.net | Date: | Thu, 11 Sep 2003 20:00:40 +0000 |
| Subject: | note 23465 deleted from language.oop by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56206@lists.php.net to get a copy of this message | ||
Note Submitter: mads@madsnielsen.nospammm.dk
----
Don't use $this to pass a reference to the current object in the object's constructor.
class parent
{
var $child;
function parent()
{
$this->child = new child(&$this);
}
}
class child
{
var $parent;
function child(&$parent)
{
$this->parent = &$parent;
}
}
$parent = new parent();
for some reason
$parent != $parent->child->parent
if you need to pass a reference to child objects, use eg. an init-function, in which &$this will
work just fine. Just don't use the constructor.