PhpStorm 警告期待错误的事情

PhpStorm warning expecting wrong thing

在一个文件中,我正在创建这样的控制器:

$controller = new typeController(true, $dbHandler, $repository);

并且 PhpStorm 突出显示 'true' 这个词说 'Expected Repository, got bool'

typeController 构造是:

public function __construct($createSession=true, $con=false, Repository $repository) {
    parent::__construct($createSession, $con);
    $this->repository = $repository;
}

那么为什么说它应该首先是 Repository 而不是 bool?为什么 $dbHandler 工作正常,我错过了什么?

编辑: 快速文档说:

public function typeController::__construct($createSession=true, $con=false, Repository $repository) typeController 

typeController 构造函数。 参数:

bool $createSession

bool $con

classes\Repository $repository

声明于:

classes\types\typeController

$repository 字段没有默认值,但它是构造函数的最后一个参数。由于其他两个具有默认值,因此 $repository 应该排在第一位,如下所示:

public function __construct(Repository $repository, $createSession=true, $con=false)

这样你就可以像这样初始化控制器:

$controller = new typeController($repository);

如果你想保留默认值,或者像这样:

$controller = new typeController($repository, true, $dbHandler);

如果你想覆盖它们。

您不能在具有默认值的构造函数参数之后放置没有默认值的构造函数参数,因为在对象实例化期间可以省略默认参数