From: matthewb at syrah dot us
Operating system: FreeBSD
PHP version: 4.3.2
PHP Bug Type: Unknown/Other Function
Bug description: call_user_func (and call_user_func_array) disrespect returned
references
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 bug report at http://bugs.php.net/?id=24631&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=24631&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=24631&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=24631&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=24631&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=24631&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=24631&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=24631&r=support
Expected behavior: http://bugs.php.net/fix.php?id=24631&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=24631&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=24631&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=24631&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24631&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=24631&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=24631&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=24631&r=gnused