开发者

Getting PDT code completion to recognise runtime return types from base class?

I've got an abstract base class:

abstract class BaseClass {
  /**
   * @return CLASSNAME
   */
  public function fluent() {
    // do stuff
    return $this;
  }
}

Generally, i would pu开发者_如何学JAVAt BaseClass where CLASSNAME is and all would be fine, PDT would pick up the phpdoc return type and happily autocomplete.

Until, that is, I subclass BaseClass and add additional methods, and code compete on an instance of the derived class. PDT will only recognise the methods from BaseClass and not those from the derived class.

What I need is something like @return self or @return this.

Does PDT have such functionality? Or is there an alternate trick without having to declare these methods in every derived class?


AFAIK there is no such feature in PDT, but you could use at least type hint:

$obj = $osomething->fluent();
/* @var $obj ChildClass */

Then you would have all methods from derived in autocompletion. I know its annoying to write this comment every time you call fluent(), but it is still better than re-defining the methods in each derived class over and over again...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜