function HelloFunc($Arg1 , $Arg2 , $Arg3 ){
echo "Arg1 : " . $Arg1 . "\n";
echo "Arg2 : " . $Arg2 . "\n";
echo "Arg3 : " . $Arg3 . "\n";
return "done";
}
Comparing Outputs
echo call_user_func("HelloFunc" , "1" , "2" , "3");
Arg1 : 1
Arg2 : 2
Arg3 : 3
done
echo call_user_func_array("HelloFunc" , "1" , "2" , "3");
Warning: call_user_func_array() expects exactly 2 parameters
My question is, the best cases to use call_user_func & call_user_func_array
I know call_user_method & call_user_method_array are depreciated and does not work in PHP7. And call_user_func & call_user_func_array do not work in older PHP.
Is that a good idea to relate following to make it compatible with most php version
call_user_method = call_user_func
call_user_method_array = call_user_func_array
Like :
function_exists('call_user_method ') ? call_user_method() : call_user_func ();
function_exists('call_user_method_array ') ? call_user_method_array () : call_user_func_array();
call_user_func_array, As the name states that it should an array. So usecall_user_func_array('funntion', $arr), For your questionecho call_user_func_array("HelloFunc" , array("1" , "2" , "3"));