note 19696 added to function.call-user-func

From: Date: Thu, 07 Mar 2002 21:23:01 +0000
Subject: note 19696 added to function.call-user-func
Groups: php.notes 
Request: Send a blank email to php-notes+get-27493@lists.php.net to get a copy of this message
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. -- http://www.php.net/manual/en/function.call-user-func.php http://master.php.net/manage/user-notes.php?action=edit+19696 http://master.php.net/manage/user-notes.php?action=delete+19696 http://master.php.net/manage/user-notes.php?action=reject+19696

« previous php.notes (#27493) next »