如何自动生成一个参数可变的函数调用
程序员文章站
2022-05-30 12:53:19
...
代码思路如下:
public function __call($method, $args) {
return $this->redis->$method($args[0][,$args[1]][,$args[2]]...]);
}
请问如何实现 $this->redis->$method() 的参数列表根据 $args 变化而自动生成函数调用
public function __call($method, $args) {
return $this->redis->$method($args[0][,$args[1]][,$args[2]]...]);
}
请问如何实现 $this->redis->$method() 的参数列表根据 $args 变化而自动生成函数调用
回复内容:
代码思路如下:
public function __call($method, $args) {
return $this->redis->$method($args[0][,$args[1]][,$args[2]]...]);
}
请问如何实现 $this->redis->$method() 的参数列表根据 $args 变化而自动生成函数调用
给个思路
class RedisClient {
protected $_redis;
public function __construct() {
$this->_redis = new Redis();
}
public function __call($method, $args) {
call_user_func_array(array($this->_redis, $method), $args);
}
}
不就是变长参数列表嘛。
上一篇: PHP怎么实现网站保存快捷方式
下一篇: sql2005 批量更新问题的解决方法
推荐阅读
-
在Python中将函数作为另一个函数的参数传入并调用的方法
-
More Effective C++----(12)理解"抛出一个异常"与"传递一个参数"或"调用一个虚函数"间的差异
-
利用可变长度参数定义一个函数,输入为任意个数的数值,功能为对输入数据求和并输出;
-
python利用可变长度参数定义一个函数,输入为任意个数的数值,功能为对输入数据求和并输出;
-
printf是如何实现可变参数的?自定义函数能否实现参数可变?【C语言】
-
编写一个用户自定义函数,该函数有三个整数参数,函数的功能是:求解这三个整数的最大值,函数的返回值为三个参数的最大值。编写一个程序,从键盘输入N组数据,每组分别是任意5个整数,通过两次调用用户自定义函数
-
JS如何生成一个不重复的ID的函数
-
Python中的函数(定义、调用、形参、实参、必选参数、默认参数、可变参数,关键字参数)
-
在Python中将函数作为另一个函数的参数传入并调用的方法
-
C++中如何清理需要销毁的对象?C++编译器是否能够自动调用某个特殊的函数进行对象的清理?