[英]Laravel app stopped working after upgrading to php 8
after updating my mac to php 8 laravel app stopped working, this is the error I'm getting:将我的 mac 更新到 php 8 laravel 应用程序停止工作后,这是我得到的错误:
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
I've tried to fix the issue by investigating the code with no luck我试图通过调查没有运气的代码来解决这个问题
THE SOLUTION解决方案
As explained here latest version of laravel 6, 7 and 8 has made changes required for php 8. all you have to do is:如此处所述,laravel 6、7 和 8的最新版本已对 php 8 进行了更改。您所要做的就是:
1- add php 8 to your composer.json
(I've kept v7.4 just in case production server does not support php 8 yet) 1- 将 php 8 添加到您的
composer.json
(我保留了 v7.4 以防生产服务器不支持 php 8)
"php": "^7.4|^8.0",
2- to run composer update
to update your laravel to the latest version 2- 运行
composer update
将您的 laravel 更新到最新版本
composer update
3- make sure update the following libraries since they exist in all laravel applications 3- 确保更新以下库,因为它们存在于所有 laravel 应用程序中
PHP to php:^8.0
Faker to fakerphp/faker:^1.9.1
PHPUnit to phpunit/phpunit:^9.3
4- check for any other library which needs to be updated, contribute if they haven't supported php 8. but you should be good to go with most of the libraries since they have active contributors. 4- 检查是否有任何其他需要更新的库,如果它们不支持,请贡献 php 8. 但是你应该对大多数库 go 很好,因为它们有活跃的贡献者。
EXPLAINING THE PROBLEM解释问题
PHP 8 introduces several improvements in PHP type systems such as the introduction of Union Types, mixed type, and a few more.
PHP 8 介绍了 PHP 类型系统的多项改进,例如联合类型、混合类型等。
With these changes, certain methods in Reflection API's ReflectionParameter yield incorrect results.
通过这些更改,Reflection API 的 ReflectionParameter 中的某些方法会产生不正确的结果。
In PHP 8, the following methods from ReflectionParameter class is deprecated:
在 PHP 8 中,ReflectionParameter class 中的以下方法已弃用:
ReflectionParameter::getClass() ReflectionParameter::isArray() ReflectionParameter::isCallable()
ReflectionParamter::getType() is the recommended way to replace the deprecated methods.
ReflectionParamter::getType() 是替换已弃用方法的推荐方法。 This method is available in PHP 7.0 and later.
此方法在 PHP 7.0 及更高版本中可用。
Check your php version in your virtual machine(xampp or server).检查虚拟机(xampp 或服务器)中的 php 版本。
php --version
Is that version PHP 8?那个版本是 PHP 8 吗? Am I right?
我对吗? That's the cause of the problem:
这就是问题的原因:
PHP 8 introduces several improvements in PHP type systems such as the introduction of Union Types, mixed type, and a few more. PHP 8 介绍了 PHP 类型系统的多项改进,例如联合类型、混合类型等。
With these changes, certain methods in Reflection API's ReflectionParameter yield incorrect results.通过这些更改,Reflection API 的 ReflectionParameter 中的某些方法会产生不正确的结果。
In PHP 8, the following methods from ReflectionParameter class is deprecated:在 PHP 8 中,ReflectionParameter class 中的以下方法已弃用:
Downgrade your php version to 7.4 and your Laravel app works like a charm!将您的 php 版本降级到 7.4,您的 Laravel 应用程序就像一个魅力!
after updating my mac to php 8 laravel app stopped working, this is the error I'm getting:将我的mac更新到 php 8 laravel 应用程序停止工作后,这是我得到的错误:
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 871
Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/.../Sites/.../vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
I've tried to fix the issue by investigating the code with no luck我试图通过调查没有运气的代码来解决这个问题
I had similar issue.我有类似的问题。 But I had already run
brew update
and brew cleanup
before I noticed the issue.但是在我注意到这个问题之前,我已经运行了
brew update
和brew cleanup
。 What I did:我做了什么:
brew cleanup
:brew cleanup
注意到这个错误:Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/node
Target /usr/local/bin/node
already exists. You may want to remove it:
rm '/usr/local/bin/node'
To force the link and overwrite all conflicting files:
brew link --overwrite heroku-node
brew link --overwrite composer
composer upgrade
composer update
That's what worked for me这对我有用
If you're using valet you should do the followings:如果您使用代客泊车服务,则应执行以下操作:
valet isolate php@7.4
valet isolate php@7.4
valet composer update
valet composer update
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.