Call_user_func is a built-in function of PHP that allows the user to call directly written functions and pass in certain parameters, and summarizes how this function is used.
The 1,call_user_func function is similar to a particular method of calling a function, using the following method:
<?phpfunction nowamagic ($a, $b) { echo $a; echo $b; } Call_user_func (' Nowamagic ', "111", "222"); Call_user_func (' Nowamagic ', "333", "444"); Show 111 222 333 444 ?>
2, call the method inside the class is rather strange, incredibly use is an array, do not know how developers are thinking, of course, save the new, but also quite innovative:
<?phpclass a { function B ($c) { echo $c; } } Call_user_func (Array ("A", "B"), "111"); Show 111 ?>
The 3,call_user_func_array function is similar to the Call_user_func, except that the parameter is passed in a different way, allowing the structure of the parameter to be clearer:
<?phpfunction A ($b, $c) { echo $b; echo $c; } Call_user_func_array (' A ', Array ("111", "222")); Showing 111 of 222
The 4,call_user_func_array function can also invoke methods within the class:
<?phpclass ClassA { function BC ($b, $c) { $BC = $b + $c; echo $bc; } } Call_user_func_array (Array (' ClassA ', ' BC '), Array ("111", "222")); Show 333 ?>
Both the 5,call_user_func function and the Call_user_func_array function support references, which makes them more functionally consistent with normal function calls:
<?phpfunction 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?>
6, in addition, both the Call_user_func function and the Call_user_func_array function support references.
<?phpfunction Increment (& $var) { $var + +;} $a = 0;call_user_func (' increment ', $a); Echo $a; 0call_user_func_array (' Increment ', array (& $a)); Can use this insteadecho $a; 1?>
PHP function Completion: Call_user_func ()