0

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 ?

MichaelLuthor
  • 416
  • 1
  • 7
  • 14

2 Answers2

2

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 { ...
ashnazg
  • 6,558
  • 2
  • 32
  • 39
  • This is a goog way, but some developers would not or forget update comment when they modify the code, then the comment method would be danger for others. – MichaelLuthor Jun 19 '13 at 01:42
  • 1
    But, because you're using __call(), you are not actually defining any method names in your code. As such, there is no place in that class to list method names, except the @method tag. If you are actually defining methods in code, then __call() should not be necessary to reach those methods. Perhaps I'm missing some aspect of your use case. – ashnazg Jun 20 '13 at 16:53
  • yeah, I should remove __call() method, or just rename to _call(). – MichaelLuthor Jun 21 '13 at 02:16
0
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.

CodeAngry
  • 12,760
  • 3
  • 50
  • 57