call_user_func

王朝百科·作者佚名  2012-05-29
窄屏简体版  字體: |||超大  

函数说明(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]

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航