使用魔术的私有/受保护成员变量的代码完成__get() [英] Code Completion for private/protected member variables when using magic __get()

查看:143
本文介绍了使用魔术的私有/受保护成员变量的代码完成__get()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用具有私有或受保护成员变量的类时,如何使用Zend Studio(或任何基于Eclipse的IDE)设置代码完成功能,而无需使用一组Getter的OR将成员vars设置为public。 p>

例如:

  class Dog {

保护$ bark ='woof!';

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

}

$ Dog = new Dog();
echo $ Dog-> bark; //< - 我想让IDE知道树皮是Dog的财产。


解决方案

魔法的代码完成方法可以通过使用 @property

  / ** 
* @property string bark
* /
class Dog {
/ * ... * /
}

$ Dog = new Dog();
echo $ Dog-> //将自动完成

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




How do I setup code completion to work on Zend Studio (or any Eclipse based IDE) when working with a class that has private or protected member variables WITHOUT resorting to a bunch of Getter's OR setting the member vars as public.

For example:

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.

解决方案

Code Completion for Magic Methods can be achieved by using the @property and @method annotation in the DocBlock of the class (not in the Method Docs).

/**
 * @property string bark
 */
class Dog {
    /* ... */
}

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

Note that there is no correlation between the actual code and the annotation. Zend Studio will show whatever you set for @property, regardless of this property existing. It will also not check if there actually is a magic method available.

这篇关于使用魔术的私有/受保护成员变量的代码完成__get()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆