note 32179 deleted from language.references.pass by sniper

From: Date: Tue, 30 Sep 2003 01:23:51 +0000
Subject: note 32179 deleted from language.references.pass by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57335@lists.php.net to get a copy of this message
Note Submitter: joachim at lous org ---- Something is very fishy with object-by-reference semantics: It doesn't seem to be possible to replace the passed object references with other references: class a{ var $val; function a($val){ $this->val = $val;} } function replace(&$src, &$dest){ $dest =& $src; } $src = new a(2); $dest = new a(1); replace($src,$dest); $src->val=5; echo $dest->val; This code prints "1", not "5". Changing the '=&' with '=' you gets you '2', as expected. I can find no way to get the actual reference across. I can work around it by returning the reference in stead, but that only works for one ref.

« previous php.notes (#57335) next »