call_user_func()

call_user_func() — Call the callback given by the first parameter.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Calls the callback given by the first parameter and passes the remaining parameters as arguments.

Signature

call_user_func(callable $callback, mixed ...$args): mixed

Parameters

ParameterTypeWhat it takes
$callbackcallableThe callable to be called.
...$argsmixedZero or more parameters to be passed to the callback.

Return value

Returns the return value of the callback.

Example

A runnable snippet:

function barber($type) { echo "You wanted a $type haircut, no problem\n"; } call_user_func('barber', "mushroom"); call_user_func('barber', "shave");

Output:

You wanted a mushroom haircut, no problem You wanted a shave haircut, no problem

See also

call_user_func_array(), is_callable()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page call_user_func() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.