php - PHPStorm type hinting subclasses of baseclass -


with respect post:

in phpstorm, how can make type hinting work when have superclass method returns different type each subclass,

this 1 edge case in phpstorm type hinting. please try follow along - i'll best clear possible:

so, i've got base abstract class:

abstract class mybasecontroller {     protected $_model;     ... } 

which class inherits from:

class mycontroller extends mybasecontroller {     $hello = 'hello';     ... } 

and further extended third class:

class mynewcontroller extends mycontroller {     public $myvar;     $this->_model = new mymodel();     ...      public function myfunc(){         // !!form underlined as: "method 'form' not found in class"!!         $form = $this->_model->form($new_variable);      } 

below sample of mymodel class:

class mymodel extends basemodel {     $world = 'world';     public function form($my_variable) {         do_something();     } 

my true question how "phpdoc" scenario:

a subclass mynewcontroller using inherited variable _model assign instance of class mymodel has unique function form. how should phpstorm find out form in mynewcontroller?

my solution far involves documenting mybasecontroller this:

abstract class mybasecontroller {     /**      * @var object      */      protected $_model;     ... } 

however think @var object broad (phpstorm won't find declaration) , guess there should better (and more specific) way this.

maybe instead do:

/**  * @var basemodel  */ 

if phpstorm had way of looking subclasses method.

any ideas? thank in advance.

you can specify property type in subclass without introducing new code, using @property annotation:

/**  * @property mymodel $_model  */ class mynewcontroller extends mycontroller 

Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -