Name

call_user_func()

Synopsis

    mixed call_user_func ( function callback [, mixed param1 [, 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.

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.