2

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 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.