在组件构造函数中,我总是为属性设置默认值(Laravel v7-8,PHP7.4)。
版本 8.1.4 Laravel9.6.0
public $type;
public $message;
public function __construct($type = 'error', $message)
{
$this->type = $type;
$this->message = $message;
}在Laravel 9(新安装)中,我尝试:
我知道这个错误:
类App\View\Components\Alert中的
无法解决的依赖关系解析[参数#0 $type ]
当我试着:<x-alert type="success" message="my message"/>,一切都好。因此,类似乎忽略了构造函数中的默认参数。我做错了什么?
发布于 2022-04-02 14:09:19
幸亏有了默哀:
“从PHP 8.0.0开始,在可选参数之后声明强制参数是不可取的。”
https://stackoverflow.com/questions/71717431
复制相似问题