Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend框架1.12。是否可以在函数init()中定义对象并将其用作全局对象_Php_Zend Framework_Phpstorm - Fatal编程技术网

Php Zend框架1.12。是否可以在函数init()中定义对象并将其用作全局对象

Php Zend框架1.12。是否可以在函数init()中定义对象并将其用作全局对象,php,zend-framework,phpstorm,Php,Zend Framework,Phpstorm,如果像这样调用函数init()中的对象,则无法使用自动完成: class IndexController extends HiNStudio_Controller { private $model_obj; public function init() { $this -> model_obj = new Default_Model_Account(); } public function indexAction() { $this -> model_obj -

如果像这样调用函数
init()中的对象,则无法使用自动完成:

class IndexController extends HiNStudio_Controller {

private $model_obj;

public function init() {
    $this -> model_obj = new Default_Model_Account();
}

public function indexAction() {
    $this -> model_obj ->  //(it should be something autocomplete here)
}
class IndexController extends HiNStudio_Controller {

private $model_obj;

public function init() {

}

public function indexAction() {
    $this -> model_obj = new Default_Model_Account();
    $this -> model_obj ->  //(autocomplete is working here)
}

如果我调用正确的函数名,代码仍然有效。例:

public function indexAction() {
    $this -> model_obj ->  checkLogin();
}
是否有在每个函数中显示自动完成函数而不是调用对象的情况,如下所示:

class IndexController extends HiNStudio_Controller {

private $model_obj;

public function init() {
    $this -> model_obj = new Default_Model_Account();
}

public function indexAction() {
    $this -> model_obj ->  //(it should be something autocomplete here)
}
class IndexController extends HiNStudio_Controller {

private $model_obj;

public function init() {

}

public function indexAction() {
    $this -> model_obj = new Default_Model_Account();
    $this -> model_obj ->  //(autocomplete is working here)
}

我对PHP不太熟悉,但我认为它与方法调用时的模型有关,因为obj不能初始化。尝试用构造函数替换函数init。
这意味着当您创建IndexController的新对象时,构造函数将始终设置model_obj变量。

类型使用PHPDoc注释提示您的变量

/** @var Default_Model_Account */
private $model_obj;
如果PhpStorm未在构造函数中初始化,或者未在初始化的同一方法中使用,则PhpStorm会释放变量类型