October 2005
Intermediate to advanced
372 pages
11h 35m
English
call_user_func()
mixed call_user_func ( functioncallback[, mixedparam1[, mixed ...]] )
The call_user_func() function is a special way to call an existing PHP function. It takes the function to call as its first parameter, with the parameters to pass into the variable function as multiple parameters to itself. For example:
$func = "str_replace";
$output_single = call_user_func($func, "monkeys", "giraffes", "Hundreds and
thousands of monkeys\n");In that example, "monkeys", "giraffes", and "Hundreds of thousands of monkeys" are the second, third, and fourth parameters to call_user_func(), but get passed into str_replace() (the function in $func) as the first, second, and third parameters.
An alternative to this function is call_user_func_array()
, where the parameters to be passed are grouped in an array.