note 19698 added to function.call-user-func
| From: | dougqh at hotmail dot com | Date: | Thu, 07 Mar 2002 22:16:14 +0000 |
| Subject: | note 19698 added to function.call-user-func | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27495@lists.php.net to get a copy of this message | ||
The previous note I posted had an error in the source code. That has been corrected in this note.
Note, that returning by reference does not work properly when the function
is called using call_user_func.
This example illustrates the problem...
$globalVar = 0;
function &staticFunction()
{
global $globalVar;
return $globalVar;
}
$result =& call_user_func( "staticFunction" );
$result = 3;
print "result:" . $result . "<br/>\n";
print "globalVar: " . $globalVar . "<br/>\n";
$result2 =& staticFunction();
$result2 = 3;
print "result2: " . $result2 . "<br/>\n";
print "globalVar: " . $globalVar . "<br/>\n";
The above code results in the following output ...
Note that $result is not a reference to $globalVar.
result:0
globalVar: 0
result2: 3
globalVar: 3
Also, the use of call_user_method is now deprecated in favor of passing
array( &$object, $method ) as the function to call_user_func. This is
reported when error reporting is set to E_ALL in the latest versions of
PHP.
--
http://www.php.net/manual/en/function.call-user-func.php
http://master.php.net/manage/user-notes.php?action=edit+19698
http://master.php.net/manage/user-notes.php?action=delete+19698
http://master.php.net/manage/user-notes.php?action=reject+19698