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

WBOY
Release: 2016-06-06 20:47:58
Original
1148 people have browsed it

代码思路如下:
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 变化而自动生成函数调用

给个思路

<code class="lang-php">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);
    }
}
</code>
Copy after login

不就是变长参数列表嘛。

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!