note 34963 added to language.oop.newref

From: Date: Wed, 13 Aug 2003 13:33:12 +0000
Subject: note 34963 added to language.oop.newref
Groups: php.notes 
Request: Send a blank email to php-notes+get-54077@lists.php.net to get a copy of this message
There is a much simpler and shorter workaround if you absolutly need the references to the constructor's $this (i.e the original object): class a { function a() { $this->self_ref = &$this; } } $a = new a; $a = &$a->self_ref; now $a points to the original object, and allows the following code to work: class a { function a($name) { $this->self_ref = &$this; $this->name = $name; $this->b = new b($this); } } class b { function b(&$a) { $this->a = &$a; } } $a = new a('a'); $a->b->a->name = 'b'; echo $a->name.'<br>'; // This would output 'a'. // Now refer $a to the real object, the same one that the b class object refers to: $a = &$a->self_ref; $a->b->a->name = 'b'; echo $a->name.'<br>'; // Now this would output 'b'. ---- Manual Page -- http://www.php.net/manual/en/language.oop.newref.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34963 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34963&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34963&report=yes

« previous php.notes (#54077) next »