call_user_func in PHP

Syntax of call_user_func

mixed call_user_func(string function[, mixed parameter1[, … mixed parameterN]])

Calls the function given in the first parameter. Additional parameters are used as such when calling the function. The comparison to check for a matching function is case-insensitive. Returns the value returned by the function

Example of call_user_func

function increment(&$var)

$a = 0;
call_user_func('increment', $a);
echo $a."\n";

// it is possible to use this instead
call_user_func_array('increment', array(&$a));
echo $a."\n";

// it is also possible to use a variable function
$increment = 'increment';
echo $a."\n";

Output call_user_func

Warning: Parameter 1 to increment() expected to be a reference, value given in …

Leave a Comment