问题
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?
回答1:
I don't think there is an easy way of doing this. However, you could try using @method tag e.g.
/**
* @method SpecializedContainer Children()
*/
class SpecializedContainer extends GeneralContainer {
protected function CreateChildren() {
return array();
}
}
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.
来源:https://stackoverflow.com/questions/4742302/php-with-netbeans-applying-new-phpdoc-without-the-actual-declaration