3

Take a look at this code example:

class basetype {
    public function method() {
        return false;
    }
}

class extendtype extends basetype {
    public function methodb() {
        return true;
    }
}

class aa {
    /**
     * @var basetype
     */
    protected $membera;
}

class bb extends aa {
    public function __constructor() {
        $this->membera = new extendtype();
    }

    public function dosomething() {
        $this->membera->methodb();
    }
}

When edited within PHPStorm I get warning that "Method methodb not found in class basetype". I work with preexisting code base and can not alter the base classes. So what can I do in order to remove this warning?

3
  • Why are you @var basetype the $membera variable? Yes, $membera is a type of basetype, but that may be confusing PHPStrorm. Just remove that and see if you get the same error. Commented Oct 2, 2015 at 15:26
  • I think you are misreading the warranting. Past it form phpstorm. At the end of the day it is just a hint, if your code works it doesn't matter. Commented Oct 2, 2015 at 15:29
  • Possible duplicate of PHPStorm type hinting subclasses of baseclass Commented May 17, 2016 at 17:39

1 Answer 1

1

You can override $membera in your class BB and give it a new doc-block with the derived type.

class bb extends aa {
    /**
     * @var extendtype
     */
    protected $membera;

    public function __constructor() {
        $this->membera = new extendtype();
    }

    public function dosomething() {
        $this->membera->methodb();
    }
}
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.