函数说明(PHP 4中,PHP5中)
call_user_func - 返回一个自定义用户函数给出的第一个参数
函数定义mixed call_user_func(回调 函数名 [,混合 参数 [,混合$ ...]])
调用该函数定义的函数参数给出一个用户。功能该函数被调用。类方法也可以使用静态调用传递数组array($classname, $methodname) 这个参数此功能。另外一个对象的实例可以被称为类方法通过传递数组array($objectinstance, $methodname) 这个参数。参数零个或多个参数传递给函数。
注意: 对于call_user_func(参数)不按引用传递。
实例说明例-1
<?php
error_reporting(E_ALL);
function increment(&$var)
{
$var++;
}
$a = 0;
call_user_func('increment', $a);
echo $a."
";
call_user_func_array('increment', array(&$a)); // You can use this instead before PHP 5.3
echo $a."
";
?>
输出:
0
1
例-2
<?php
function barber($type)
{
echo "You wanted a $type haircut, no problem
";
}
call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
?>
输出:
You wanted a mushroom haircut, no problem
You wanted a shave haircut, no problem[1]