note 19696 deleted from function.call-user-func by didou
| From: | didou@php.net | Date: | Thu, 29 May 2003 22:46:00 +0000 |
| Subject: | note 19696 deleted from function.call-user-func by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-49366@lists.php.net to get a copy of this message | ||
Note Submitter: dougqh@hotmail.com
----
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:" . $globalVar . "<br/>\n";
print "globalVar: " . $globalVar . "<br/>\n";
$result2 =& staticFunction();
$result2 = 3;
print "result2: " . $globalVar . "<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.