簡體   English   中英

使用magic __get()時私有/受保護成員變量的代碼完成

[英]Code Completion for private/protected member variables when using magic __get()

在處理具有私有或受保護成員變量的類時,如何設置代碼完成以在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.

代碼完成的魔術方法可以使用來實現@property@method注釋中的類(而不是在方法文檔)的文檔塊。

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

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

請注意,實際代碼和注釋之間沒有相關性。 Zend Studio將顯示您為@property設置的任何內容,無論此屬性是否存在。 它也不會檢查是否有可用的魔法。

使用@property注釋在Zend Studio中完成代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM