|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-07-12 22:10 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 09:00:01 2025 UTC |
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.