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

<?php
error_reporting(E_ALL);
function increment(&$var)
{
    $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';
$increment($a);
echo $a."\n";
?>

Output call_user_func

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

Leave a Comment