Laravel7项目Composer dump-autoload报错:PHP版本切换后仍异常
Laravel 7 项目虚拟主机PHP版本切换后Composer兼容性问题
- 项目背景:Laravel 7部署在虚拟主机子目录,此前运行正常;主机商将全局PHP版本升级至v8.1.12后,执行
composer dump-autoload出现报错。 - 当前状态:已将项目对应的PHP版本切换回7.4甚至7.3,但执行
composer update时,在Generating optimized autoload files步骤会触发以下弃用通知:
Deprecation Notice: Return type of Illuminate\Container\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/rootfolder/public_html/projectfolder/vendor/laravel/framework/src/Illuminate/Container/Container.php:1270 Deprecation Notice: Return type of Illuminate\Container\Container::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/rootfolder/public_html/projectfolder/vendor/laravel/framework/src/Illuminate/Container/Container.php:1281 Deprecation Notice: Return type of Illuminate\Container\Container::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the [\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/rootfolder/public_html/projectfolder/vendor/laravel/framework/src/Illuminate/Container/Container.php:1293 Deprecation Notice: Return type of Illuminate\Container\Container::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home1/rootfolder/public_html/projectfolder/vendor/laravel/framework/src/Illuminate/Container/Container.php:1306 > @php artisan package:discover --ansi
- 环境矛盾:本地执行
php --version显示当前PHP版本为7.3.33,但Composer似乎仍在使用主机根目录的PHP 8.1.12版本。 - 已尝试方案:修改
composer.json中的PHP版本约束、执行composer update/composer install/composer self-update、清除Composer缓存、联系主机技术支持,均未解决问题。 - 需求:项目依赖暂未适配Laravel 8/9,不想升级整个项目,寻求可行的技术解决方案。
内容的提问来源于stack exchange,提问作者Urget
相关产品推荐
相关产品推荐

