note 45291 added to language.oop.newref
| From: | denisatyum at osu1 dot php dot net | Date: | Wed, 01 Sep 2004 10:22:14 +0000 |
| Subject: | note 45291 added to language.oop.newref | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75835@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.oop.newref.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45291
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45291&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45291&report=yes
Search -- http://master.php.net/manage/user-notes.php