热门标签 | HotTags
当前位置:  开发笔记 > 后端 > 正文

如何自动生成一个参数可变的函数调用

代码思路如下:publicfunction__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);
    }
}

不就是变长参数列表嘛。

推荐阅读
author-avatar
坑爹的马_782
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有