ID: 24631
Updated by: [EMAIL PROTECTED]
Reported By: matthewb at syrah dot us
-Status: Open
+Status: Closed
-Bug Type: Unknown/Other Function
+Bug Type: Scripting Engine problem
Operating System: FreeBSD
PHP Version: 4.3.2
New Comment:
Fixed in ZE2 (PHP5).
Previous Comments:
------------------------------------------------------------------------
[2003-07-12 21:46:02] matthewb at syrah dot us
Description:
------------
call_user_func and call_user_func do respect functions that return
references. That is, function foo that returns a references to an
object, does not return a reference to an object when foo is called via
call_user_func. Instead, foo called via call_user_func returns a
"copy" of the object. (I'm not sure "copy" is the right word.) See
the code example for a concise example of the problem.
Note: this may cease to be a problem in PHP5, as it is my understanding
that objects will be passed/returned by reference by default.
If my you do not understand my description and my reproduce code, email
me and I will happily explain it to you.
Many thanks.
Reproduce code:
---------------
<?php
$x->var = 1;
function & foo (&$x) {
return $x; }
$y =& foo ($x);
print "y->var = ". $y->var. " <br>\n";
$x->var++;
print "y->var = ". $y->var. " <br>\n";
$z =& call_user_func ("foo", &$x);
print "z->var = ". $z->var. " <br>\n";
$x->var++;
print "z->var = ". $z->var. " <br>\n";
$w =& call_user_func_array ("foo", array (&$x));
print "w->var = ". $w->var. " <br>\n";
$x->var++;
print "w->var = ". $w->var. " <br>\n";
?>
Expected result:
----------------
y->var = 1 <br>
y->var = 2 <br>
z->var = 2 <br>
z->var = 3 <br>
w->var = 3 <br>
w->var = 4 <br>
Note that I expect z->var and w->var to get inceremented just as y->var
gets inceremented.
Actual result:
--------------
y->var = 1 <br>
y->var = 2 <br>
z->var = 2 <br>
z->var = 2 <br>
w->var = 3 <br>
w->var = 3 <br>
Note that in reality, however, z->var and w-> did not get inceremented.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24631&edit=1