1. call_user_func
Copy code The code is as follows:
function a($b,$c){
echo $b;
echo $c;
}
call_user_func('a', "111","222");
call_user_func('a', "333","444");
//Display 111 222 333 444
?>
It’s strange to call the method inside the class. It actually uses array. I don’t know what the developer thought about it. Of course, new is omitted, which is also full of novelty:
Copy code The code is as follows:
class a {
function b($c){
echo $ c;
}
}
call_user_func(array("a", "b"),"111");
//Display 111
?>
2. call_user_func_array
The call_user_func_array function is very similar to call_user_func, except that the parameters are passed in a different way to make the structure of the parameters clearer:
Copy code Code As follows:
function a($b, $c){
echo $b;
echo $c;
}
call_user_func_array('a', array( "111", "222"));
//Display 111 222
?>
The call_user_func_array function can also call methods inside the class
Copy code The code is as follows:
Class ClassA{
function bc($b, $c) {
$bc = $b + $c;
echo $bc;
}
}
call_user_func_array(array('ClassA','bc'), array("111", "222") );
//Display 333
?>
Both the call_user_func function and the call_user_func_array function support references, which makes them more functionally consistent with ordinary function calls:
Copy code The code is as follows:
function a(&$b){
$b++;
}
$c = 0;
call_user_func('a', &$c);
echo $c;//Display 1
call_user_func_array('a', array(&$c));
echo $c;//Display 2
http://www.bkjia.com/PHPjc/736827.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736827.htmlTechArticle1. call_user_func Copy code The code is as follows: function a($b,$c){ echo $b; echo $ c; } call_user_func('a', "111","222"); call_user_func('a', "333","444"); //Display 111 222 333 444 ? Call...