Laravel 应用程序在升级到 php 8 后停止工作 [英] Laravel app stopped working after upgrading to php 8

查看:46
本文介绍了Laravel 应用程序在升级到 php 8 后停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将我的 mac 更新为 php 8 laravel 应用程序后停止工作,这是我收到的错误:

after updating my mac to php 8 laravel app stopped working, this is the error I'm getting:

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

推荐答案

解决方案

正如这里 最新版本的 Laravel 6、7 和 8 所解释的那样php 8 所需的更改.您所要做的就是:

As explained here latest version of laravel 6, 7 and 8 has made changes required for php 8. all you have to do is:

1- 将 php 8 添加到您的 composer.json(我保留了 v7.4,以防生产服务器尚不支持 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)

"php": "^7.4|^8.0",

2- 运行 composer update 将你的 Laravel 更新到最新版本

2- to run composer update to update your laravel to the latest version

composer update

3- 确保更新以下库,因为它们存在于所有 Laravel 应用程序中

3- make sure update the following libraries since they exist in all laravel applications

PHP to php:^8.0
Faker to fakerphp/faker:^1.9.1
PHPUnit to phpunit/phpunit:^9.3

4- 检查是否有任何其他需要更新的库,如果它们不支持 php 8,请贡献.但是你应该使用大多数库,因为它们有活跃的贡献者.

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.

解释问题

此处所述

PHP 8 对 PHP 类型系统进行了多项改进,例如引入了联合类型、混合类型等.

PHP 8 introduces several improvements in PHP type systems such as the introduction of Union Types, mixed type, and a few more.

通过这些更改,反射 API 中的某些方法ReflectionParameter 产生错误的结果.

With these changes, certain methods in Reflection API's ReflectionParameter yield incorrect results.

在 PHP 8 中,以下来自 ReflectionParameter 类的方法是已弃用:

In PHP 8, the following methods from ReflectionParameter class is deprecated:

ReflectionParameter::getClass()
ReflectionParameter::isArray()
ReflectionParameter::isCallable()

ReflectionParamter::getType() 是推荐的替代方法弃用的方法.此方法在 PHP 7.0 及更高版本中可用.

ReflectionParamter::getType() is the recommended way to replace the deprecated methods. This method is available in PHP 7.0 and later.

这篇关于Laravel 应用程序在升级到 php 8 后停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆