In other class, PhpStorm can identify __construct() function, but in yaf controller it can not identify the initialization method init(), resulting in the init() can not trace initialization operation.
class TestController extends Yaf_Controller_Abstract{
private $model;
public function init() {
$this->model = new TestModel();
}
public function test(){
$this->model->testDeclaration();
}
}
class TestModel{
public function testDeclaration(){
}
}
In this example, I want use 'go to declaration' from test function $this->model->testDeclaration(); to testDeclaration() function in TestModel class. But it does not work.
PhpStorm tells me:
Cannot find declaration to go to
How can I use 'go to declaration' correctly here?
PhpStorm has special treatment for
__constructor()-- it tracks what type class variable/property will get if it will have any assignment operations within the method body.For example, in this code it knows that
$this->modelwill be instance ofTestModelclass -- IDE keeps this info even outside of the__construct()method body.For other methods, like
init()in your case, such info gets discarded outside (so it's local to the method body only).You can easily resolve this by using simple PHPDoc comment with
@vartag where you will provide type hint formodelproperty:Make a habit of providing type hint for all properties/class variables, even if IDE autodetects its' type -- it helps IDE in long run.
https://phpdoc.org/docs/latest/references/phpdoc/tags/var.html