Php 与 NetBeans:在没有实际声明的情况下应用新的 PhpDoc

发布于 2024-10-12 17:57:01 字数 932 浏览 6 评论 0原文

有没有一种方法可以应用新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2024-10-19 17:57:01

我认为没有一个简单的方法可以做到这一点。但是,您可以尝试使用 @method 标记,例如

     /**
     * @method SpecializedContainer Children() 
     */
    class SpecializedContainer extends GeneralContainer {

        protected function CreateChildren() {
            return array();
        }

    }

您应该记住,@method 标签应该用于暗示魔术方法,而不是父类方法的新返回类型。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文