note 45291 deleted from language.oop.newref by danbrown
| From: | danbrown@php.net | Date: | Sat, 07 Nov 2009 19:11:10 +0000 |
| Subject: | note 45291 deleted from language.oop.newref by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162584@lists.php.net to get a copy of this message | ||
Note Submitter: denis at yum
----
Construction Methods
In case of PHP versions earlier 5.x (or both) you have to consider, that an instance of a class is
not fully allocated while the construction method(s) aren't finished.
For example, this solution could fail:
class Child
{
var $c;
function Child(&$parent)
{
$this->c = &$parent;
}
}
class Test
{
var $a;
var $var;
function Test ()
{
$this->var = 123;
$this->a = &new Child($this);
}
}
$b = &new Test();
$b->a->c->var = 456;
echo $b->var;
[outputs: 123]
In order of really allocated instance references, append referenced objects after (and not during)
the construction.