Lu4
Lu4

Reputation: 15032

Php with NetBeans: Applying new PhpDoc without the actual declaration

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?

Upvotes: 2

Views: 699

Answers (1)

Marcin
Marcin

Reputation: 238209

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.

Upvotes: 5

Related Questions