call_user_func — 把第一个参数作为回调函数调用

时间:2023-03-09 16:57:23
call_user_func — 把第一个参数作为回调函数调用

call_user_func — 把第一个参数作为回调函数调用

说明

mixed call_user_func ( callable $callback [, mixed $parameter [, mixed $... ]] )

第一个参数 callback 是被调用的回调函数,其余参数是回调函数的参数。

参数

callback

将被调用的回调函数(callable)。

parameter

0个或以上的参数,被传入回调函数。

Note:

请注意,传入call_user_func()的参数不能为引用传递。

Example #1 call_user_func() 的参考例子

<?php
error_reporting(E_ALL);
function increment(&$var)
{
$var++;
} $a = 0;
call_user_func('increment', $a);
echo $a."\n"; call_user_func_array('increment', array(&$a)); // You can use this instead before PHP 5.3
echo $a."\n";
?>

以上例程会输出:

0
1 转:http://www.php.net/manual/zh/function.call-user-func.php