Php with NetBeans: Applying new PhpDoc without the actual declaration

醉酒当歌 提交于 2019-12-24 03:36:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!