Question

I wrote a class like this :

class config {
    private $conf;

    public function __call( $confName, $args ){
        if (  0 == count($args) && isset($this->conf[$confName]) ){
            return $this->conf[$confName];
        }
        else {
            $this->conf[$confName] = $args[0];
            return $this;
        }
    }
}

and $conf = new config();

but I wanna get the suggest list when I input $conf->,

is there any ideal or it's impossible to do that ?

Was it helpful?

Solution 2

class config {
    private $conf;

    public function none_existent_method1(){
        // forward the call to __call(__FUNCTION__, ...)
        return call_user_func(array($this, '__call'),
            __FUNCTION__, func_get_args());
    }

    public function none_existent_method2(){
        // forward the call to __call(__FUNCTION__, ...)
        return call_user_func(array($this, '__call'),
            __FUNCTION__, func_get_args());
    }

    public function __call( $func, $args ){
        if (  0 == count($args) && isset($this->conf[$func]) ){
            return $this->conf[$func];
        }
        else {
            $this->conf[$func] = $args[0];
            return $this;
        }
    }
}

Just add the methods and forward them to __call yourself.

There are other ways but all require you declare the functions.

OTHER TIPS

Assuming Zend Studio honors the @method tag in the class docblock, like Eclipse PDT does, then perhaps that will give you what you're after.

/**
 * Config class
 * @method mixed aMagicMethod()  a magic method that could return just about anything
 * @method int   anotherMethod() a magic method that should always return an integer
 */
class config { ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top