call_user_func_array()
call_user_func_array() — Call a callback with an array of parameters.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.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 with the parameters in args.
Signature
call_user_func_array(callable $callback, array $args): mixed
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $callback | callable | The callable to be called. |
| $args | array | The parameters to be passed to the callback, as an array. |
Return value
Returns the return value of the callback, or false on error.
Example
A runnable snippet:
function foobar($arg, $arg2) { echo __FUNCTION__, " got $arg and $arg2\n"; } class foo { function bar($arg, $arg2) { echo __METHOD__, " got $arg and $arg2\n"; } } // Call the foobar() function with 2 arguments call_user_func_array("foobar", array("one", "two")); // Call the $foo->bar() method with 2 arguments $foo = new foo; call_user_func_array(array($foo, "bar"), array("three", "four"));
Output:
foobar got one and two foo::bar got three and four
Changelog
| Version | Change |
|---|---|
| 8.0.0 | args keys will now be interpreted as parameter names, instead of being silently ignored. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page call_user_func_array() (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.