ID: 23705
Updated by: [EMAIL PROTECTED]
Reported By: joachim at lous dot org
-Status: Closed
+Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: *
PHP Version: 5.0.0b2-dev, 4.3.3RC2-dev
New Comment:
Not bug -> bogus.
Previous Comments:
------------------------------------------------------------------------
[2003-08-04 03:32:02] [EMAIL PROTECTED]
It's not a bug.
Assigning by reference breaks any previous references that may have
existed. So the implementation of replace() won't really work, as
$dest ends up being a referenec to $src, but only locally in the
replace() function, without effecting the global $dest.
I can't think of an easy way of achieving replace() right now, but
either way, the behavior you're experiencing is intended.
FWIW, in PHP 5, it would be practical to implement replace() with
simple assignment (=) instead of assign-by-ref (=&), if you're dealing
with objects.
------------------------------------------------------------------------
[2003-07-13 00:14:58] [EMAIL PROTECTED]
Same result with ZE2.
------------------------------------------------------------------------
[2003-05-19 14:59:47] joachim at lous dot org
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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23705&edit=1