|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-07-13 00:14 UTC] sniper@php.net
[2003-08-04 03:32 UTC] zeev@php.net
[2003-08-05 10:23 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 20:00:01 2025 UTC |
It doesn't seem to be possible to replace a passed object references with a different one. I expected the following code to print "5": 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; In stead it prints "1". Changing the '=&' to '=', it prints '2', as expected. Surely this must be a bug? If not, is there really no way to get the reference across? I need this for building trees: passing the current node pointer, have the function change the tree and make the ref point to a new current node. I can work around it by returning the new reference in stead, but that only works for one ref. Using binary installer from website.