使用NetBeans的Php:在没有实际声明的情况下应用新的PhpDoc [英] Php with NetBeans: Applying new PhpDoc without the actual declaration

查看:87
本文介绍了使用NetBeans的Php:在没有实际声明的情况下应用新的PhpDoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以应用新的PhpDoc而无需重新声明方法,例如,我有一个类:

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;
    }
}

通过以下方式覆盖"CreateChildren"方法后:

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()
    }
}

子项"方法现在将返回"SpecializedChildren"的对象.但是为了给NetBeans一个提示,我也不得不重写"Children"方法,并使用PhpDoc给它一个提示.有没有一种方法可以提示NetBeans告诉它基本方法现在将返回其他类型,而无需实际覆盖该方法?

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?

推荐答案

我认为没有简单的方法可以做到这一点.但是,您可以尝试使用 @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();
        }

    }

您应该记住,虽然@method标记应用于提示魔术方法,而不是从父类返回新的方法类型.

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.

这篇关于使用NetBeans的Php:在没有实际声明的情况下应用新的PhpDoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆