PHP 构造中的未定义变量

PHP undefined variable in construct

这是我的代码:

<?php
require dirname(__DIR__).'/config/Redirect.php';

class Parsing {

    private $controller = null;
    private $model = null;
    private $parameters = array();

    private $redirect;

    public function __construct() {
        $this->redirect = new Redirect($controller, $model, $parameters); //error is on this line
    }

}
?>

我得到的错误是这样的(我删除了行号,但我在上面的代码中注释了错误所在):

Notice: Undefined variable: controller in /var/www/html/application/config/Parsing.php on line #

Notice: Undefined variable: model in /var/www/html/application/config/Parsing.php on line #

Notice: Undefined variable: params in /var/www/html/application/config/Parsing.php on line #

似乎已经在其上方定义了控制器,例如 private $controller = null; 和所有其他控制器。可能是什么问题?

将行更改为:

$this->redirect = new Redirect($this->controller, $this->model, $this->parameters);

使用$this关键字调用Class级变量

public function __construct() {
        $this->redirect = new Redirect($this->controller, $this->model, $this->parameters); 
    }

您需要 $this 关键字,例如 $this->controller$this->model$this->parameters

public function __construct() {
        $this->redirect = new Redirect($this->controller, $this->model, $this->parameter); //error is on this line
}