想写一则API共通函数API正常调用是这样的
$api->a(x1,x2)
$api->b(x1,x2,x3,x4,x5)我想写一个共通函数d($fun,参数){
$api->$fun(参数)
}参数那个地方如何处理 请高手赐教
$api->a(x1,x2)
$api->b(x1,x2,x3,x4,x5)我想写一个共通函数d($fun,参数){
$api->$fun(参数)
}参数那个地方如何处理 请高手赐教
解决方案 »
- 关于上载分类体系类别层次结构(多叉树)的文本文件,这个题目实在搞不懂,求点思路~~
- 怎么用include()调用页脚并让页脚显示在网页最下边页脚处??
- 怎么删除邮件服务器上的邮件
- phpinfo()显示Configuration File (php.ini)路径是/usr/local/php/lib,可这个路径下没有php.ini文件?
- php echo输出html问题 在线结贴
- 走动的时间
- 唠叨、神仙等等的高手请帮忙看看SQL
- 大家有没有打开服务器上的一个文档
- 怎样对 web 页面中的图象进行保护,阻止非授权下载?
- 正则匹配<a>标签内的所有内容
- base64解密后末尾生成
- smarty mysql 赋值 改变条件
func_get_arg
func_get_args
func_num_args
(PHP 4, PHP 5)call_user_func — Call a user function given by the first parametermixed call_user_func ( callback $function [, mixed $parameter [, mixed $... ]] )
Call a user defined function given by the function parameter.
static $api;
if(!$api)
{
$api = new api();
}
$args = func_get_args();
$fun = array_shift($args);
if(method_exists( $api,$fun))
{
call_user_func_array(array($api,$fun),$args);
}
else
{
echo "You are calling a unknow method '{$fun}'";
}
}class api
{
function a($x1,$x2)
{
$args = func_get_args();
echo implode(' ', $args);
}
function b($x1,$x2,$x3,$x4,$x5)
{
$args = func_get_args();
echo implode(' ', $args);
}
}d('a','hello','world');
echo "<br/>";
d('b','hey','dude','are','you','there?');
echo "<br/>";
d('c','???');
function d() {
$p = func_get_args();
$fun = array_unshift($p);
if( method_exists($this, $fun))
return call_user_func_array(array($this, $fun), $p);
if(function_exists($fun))
return call_user_func_array($fun, $p);
exit("方法(函数) $fun 未定义");
}
}