note 32179 added to language.references.pass
| From: | joachim at rack1 dot php dot net | Date: | Mon, 19 May 2003 19:39:28 +0000 |
| Subject: | note 32179 added to language.references.pass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48606@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.references.pass.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32179
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32179&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32179&report=yes