Php 使用magic _get()时私有/受保护成员变量的代码完成

Php 使用magic _get()时私有/受保护成员变量的代码完成,php,eclipse,zend-studio,code-completion,Php,Eclipse,Zend Studio,Code Completion,在使用具有私有或受保护成员变量的类时,如何设置代码完成以在Zend Studio(或任何基于Eclipse的IDE)上工作,而无需求助于一堆Getter或将成员变量设置为public 例如: class Dog { protected $bark = 'woof!'; public function __get($key) { if (isset($this->$key)) { return $this->$key;

在使用具有私有或受保护成员变量的类时,如何设置代码完成以在Zend Studio(或任何基于Eclipse的IDE)上工作,而无需求助于一堆Getter或将成员变量设置为public

例如:

class Dog {

    protected $bark = 'woof!';

    public function __get($key) {
        if (isset($this->$key)) {
            return $this->$key;
        }
    }

}

$Dog = new Dog();
echo $Dog->bark; // <-- I want the IDE to "know" that bark is a property of Dog.
类狗{
受保护的$bark='woof!';
公共功能获取($key){
如果(isset($this->$key)){
返回$this->$key;
}
}
}
$Dog=新狗();

回声$Dog->bark;// 可以通过在类的DocBlock中(而不是在方法文档中)使用和注释来完成Magic方法的代码完成

请注意,实际代码和注释之间没有相关性。Zend Studio将显示您为
@property
设置的任何内容,而不管该属性是否存在。它也不会检查是否真的有一种神奇的方法可用


@Matthieu它也应该适用于Eclipse。但是不要把我的想法强加给我。是的,它在EclipsePDT中工作。我知道这是可能的,但我正在到处寻找。类上的@method注释对于奇特的抽象/继承方法来说是一个惊人的解决方案。
/**
 * @property string bark
 */
class Dog {
    /* ... */
}

$Dog = new Dog();
echo $Dog-> // will autocomplete now