Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

call_user_func()

Invoke a callable with the supplied arguments and return its result.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

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

Invoke a callable with the supplied arguments and return its result. This dispatcher passes arguments by value, so a callback that requires a reference cannot use it to change the caller’s variable. A direct invocation preserves reference parameters. An argument array containing a reference also works with call_user_func_array().

Signature

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

Example output

[4,5]

Examples

<?php
$bump=function (&$n) { ++$n; }; $n=4;
set_error_handler(fn($level)=>$level===E_WARNING);
call_user_func($bump,$n); restore_error_handler(); $after=$n;
call_user_func_array($bump,[&$n]); echo json_encode([$after,$n]);

Result

[4,5]

Sources