Php 与 NetBeans:在没有实际声明的情况下应用新的 PhpDoc
有没有一种方法可以应用新的 PhpDoc 而无需重新声明方法,例如我有一个类:
class GeneralContainer {
private $children;
public function __construct() {
$this->children = $this->CreateChildren();
}
protected function CreateChildren() {
return new GeneralChildren($this);
}
/**
* @return GeneralChildren
*/
public function Children() {
return $this->children;
}
}
按以下方式重写“CreateChildren”方法后:
class SpecializedContainer extends GeneralContainer {
protected function CreateChildren() {
return new SpecializedChildren($this);
}
/**
* @return SpecializedChildren
*/
public function Children() {
return parent::Children()
}
}
“Children”方法现在将返回“SpecializedChildren”的对象。但为了向 NetBeans 提供提示,我还有义务重写“Children”方法并使用 PhpDoc 为其提供提示。有没有办法向 NetBeans 提供提示,告诉它基方法现在将返回其他类型,而无需实际重写该方法?
Is there a way to apply new PhpDoc without redeclaration of method, for instance I have a class which:
class GeneralContainer {
private $children;
public function __construct() {
$this->children = $this->CreateChildren();
}
protected function CreateChildren() {
return new GeneralChildren($this);
}
/**
* @return GeneralChildren
*/
public function Children() {
return $this->children;
}
}
After overriding the "CreateChildren" method the following way:
class SpecializedContainer extends GeneralContainer {
protected function CreateChildren() {
return new SpecializedChildren($this);
}
/**
* @return SpecializedChildren
*/
public function Children() {
return parent::Children()
}
}
The "Children" method will now return object of "SpecializedChildren". But for the sake of giving a hint to NetBeans I'm obligated also to override the "Children" method and give it a hint using PhpDoc. Is there a way to give a hint to NetBeans telling it that the base method will now return other type without actually overriding the method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为没有一个简单的方法可以做到这一点。但是,您可以尝试使用 @method 标记,例如
您应该记住,@method 标签应该用于暗示魔术方法,而不是父类方法的新返回类型。
I don't think there is an easy way of doing this. However, you could try using @method tag e.g.
You should remember though that @method tag should be used to hint about magic methods rather than a new return types of methods from parent class.