note 20558 rejected from language.references by didou

From: Date: Tue, 03 Jun 2003 21:53:32 +0000
Subject: note 20558 rejected from language.references by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-49662@lists.php.net to get a copy of this message
Note Submitter: info@paralight.ru ---- A have found interesting strange in references to classes. class Child{ function Child(&$parent) { $this->parent=&$parent; $this->parent->var=10; } function doit() { $this->parent->var=20; } } class A{ function A() { $this->child=new Child($this); } function doit() { $this->child->doit(); echo $this->var; } } $a = new A; $a->doit(); ----------------- In result we have 10, not 20. And, if we call $a->doit(); from constructor À(): function A() { $this->child=new Child($this); $this->doit(); } we resulting 20. The way to takearound this is make empty constructor, move all from it to function constr(), and run some like: $a=new A; $a->me=&$a; $a->constr(); $a->doit(); in constr() we have $this->child=new Child($this->me); [not Child($this)]. and, as result we have 20 as would be expected. That's this? Am I missunderstand something or it is PHP bug?

« previous php.notes (#49662) next »