call_user_func用法

在PHP 4, PHP 5, PHP 7中,call_user_func — 把第一个参数作为回调函数调用。

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

第一个参数 callback 是被调用的回调函数,其余参数是回调函数的参数,传入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";
//You can use this instead before PHP 5.3
call_user_func_array('increment', array(&$a));
echo $a."\n";
?>

以上例程会输出:

0
1

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.