RT
function 1 :
$class->$func()
function 2:
//Simple callback
call_user_func($func)
//Static class method call
call_user_func(array($class,$func))
//Object method call
$class = new MyClass();
call_user_func(array($class, $func));
Is there a difference? I want to see the sourcecode(https://github.com/php/php-src) should we do?
call_user_func_arrayis very slow performance-wise, that’s why in many cases you want to go with explicit method call. But, sometimes you want to pass arbitrary number of arguments passed as an array, e.g.I’d go with checking
$nargsup to 5 (it’s usually unlikely that a function in PHP accepts more than 5 arguments, so in most cases we will call a method directly without usingcall_user_func_arraywhich is good for performance)The result of
$class->method($arg)is the same ascall_user_func_array(array($class,'method'), array($arg)), but the first one is faster.