ES0en calls the function example from a string
- 2021-01-18 06:21:44
- OfStack
1. call_user_func
function a($b,$c){
echo $b;
echo $c;
}
call_user_func('a', "111","222");
call_user_func('a', "333","444");
// According to 111 222 333 444
?>
It is a strange way to call a method inside a class. It is a strange way to call a method inside a class. It is a strange way to call a method inside a class.
class a {
function b($c){
echo $c;
}
}
call_user_func(array("a", "b"),"111");
// According to 111
?>
2. call_user_func_array
The call_user_func_array function is similar to the call_user_func function, except that the arguments are passed in a different way to make the structure of the arguments clearer:
function a($b, $c){
echo $b;
echo $c;
}
call_user_func_array('a', array("111", "222"));
// According to 111 222
?>
The call_user_func_array function can also call methods within a class
Class ClassA{
function bc($b, $c) {
$bc = $b + $c;
echo $bc;
}
}
call_user_func_array(array('ClassA','bc'), array("111", "222"));
// According to 333
?>
Both the call_user_func and call_user_func_array functions support references, which makes them more functional than normal function calls:
function a(&$b){
$b++;
}
$c = 0;
call_user_func('a', &$c);
echo $c;// According to 1
call_user_func_array('a', array(&$c));
echo $c;// According to 2