Laravel 5.4发送邮件触发FatalErrorException错误求助
Hey there, I’ve dealt with similar compatibility kinks before, so let’s break down what’s going on and how to fix it.
What’s Causing the Error?
The error message "带类类型提示的参数默认值只能为NULL" (translated: "Parameter default values with class type hints can only be NULL") stems directly from PHP 5.6’s limitations. PHP 5.6 doesn’t allow non-null default values for parameters that have a class/interface type hint—this feature was added in PHP 7.0.
The issue comes from the symfony/css-selector package: if it’s been updated to a version that requires PHP 7.0+, its code will use syntax that breaks in your PHP 5.6 environment. Even though Laravel 5.4 supports PHP 5.6, newer versions of its dependencies might not.
Step-by-Step Fix
- Open your project’s
composer.jsonfile and look for thesymfony/css-selectordependency. We need to lock it to a version compatible with PHP 5.6 (Symfony 3.x series works perfectly here). - Update the dependency line to:
"symfony/css-selector": "^3.4" - Run this command in your project root to update just that package to a compatible version:
composer update symfony/css-selector - If you still run into issues, double-check other Symfony-related dependencies in
composer.json—make sure none are set to versions requiring PHP 7.0+. Laravel 5.4 is built to work with Symfony 3.x packages.
Symfony 3.4 is a long-term support (LTS) version fully compatible with PHP 5.6, so it won’t use the newer syntax that’s triggering your fatal error when sending emails.
内容的提问来源于stack exchange,提问作者Ritchie

