Laravel 9:组件构造函数默认参数

use*_*413 -1 php php-8.1 laravel-9

在组件构造函数中,我总是设置属性的默认值(Laravel v7-8,PHP 7.4)。

版本 PHP 8.1.4 Laravel 9.6.0

public $type;
public $message;

public function __construct($type = 'error', $message)
{
    $this->type = $type;
    $this->message = $message;
}
Run Code Online (Sandbox Code Playgroud)

在 Laravel 9(新安装)中,当我尝试:

我收到此错误:

无法解析的依赖关系正在解析 App\View\Components\Alert 类中的 [参数 #0 [ $type ]]

当我尝试: 时 <x-alert type="success" message="my message"/>,一切都好。所以看来该类忽略了构造函数中的默认参数。我究竟做错了什么?

use*_*413 5

感谢医疗:

“从 PHP 8.0.0 开始,不推荐在可选参数之后声明强制参数。”