PhpStorm不支持yaf';s初始方法

PhpStorm不支持yaf';s初始方法,phpstorm,yaf,Phpstorm,Yaf,在另一个类中,PhpStorm可以识别\u construct()函数,但在yaf控制器中,它无法识别初始化方法init(),导致init()无法跟踪初始化操作 class TestController extends Yaf_Controller_Abstract{ private $model; public function init() { $this->model = new TestModel(); } public funct

在另一个类中,PhpStorm可以识别
\u construct()
函数,但在yaf控制器中,它无法识别初始化方法
init()
,导致
init()
无法跟踪初始化操作

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(){
    }
}
在本例中,我希望使用测试函数
$this->model->testDeclaration()中的“
转到声明”
testDeclaration()
类中的
TestModel
函数。但它不起作用

PhpStorm告诉我:

找不到要转到的声明

在这里如何正确使用“转到声明”

在另一个类中,PhpStorm可以识别
\u construct()
函数,但在yaf控制器中,它无法识别初始化方法
init()
,导致
init()
无法跟踪初始化操作

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(){
    }
}
PhpStorm对
\u constructor()
进行了特殊处理——它跟踪在方法体中执行任何赋值操作时类变量/属性将获得的类型

例如,在这段代码中,它知道
$this->model
将是
TestModel
类的实例——IDE甚至将此信息保存在
\u construct()
方法体之外

对于其他方法,比如在您的例子中的
init()
,这些信息会在外部被丢弃(因此它只是方法体的本地信息)


您可以通过使用带有
@var
标记的简单PHPDoc注释轻松解决此问题,其中您将为
模型
属性提供类型提示:

/** @var \TestModel Optional description here */
private $model;
养成为所有属性/类变量提供类型提示的习惯,即使IDE自动检测到它的“类型”——从长远来看,这有助于IDE


非常感谢,这样可以@张轩铭 如果它解决了你的问题,把这个答案标记为接受。