简体   繁体   English

Laravel 应用程序在升级到 php 8 后停止工作

[英]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解释问题

as described here如此所述

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 中的以下方法已弃用:

  • ReflectionParameter::getClass()反射参数::getClass()
  • ReflectionParameter::isArray()反射参数::isArray()
  • ReflectionParameter::isCallable()反射参数::isCallable()
  • ReflectionParamter::getType()反射参数::getType()

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 updatebrew cleanup What I did:我做了什么:

  1. I noticed this error from 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
  1. I ran the commands:我运行了命令:
brew link --overwrite composer
composer upgrade
composer update

That's what worked for me这对我有用

If you're using valet you should do the followings:如果您使用代客泊车服务,则应执行以下操作:

  1. Downgrade from php8+ to php7.4 valet isolate php@7.4从 php8+ 降级到 php7.4 valet isolate php@7.4
  2. Then run composer update using valet valet composer update然后使用 valet valet composer update

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 php脚本中的SQL在服务器上升级php版本后停止工作 - SQL in php script stopped working after upgrading php version on the server imagecreatefromjpeg() 在升级到 PHP 7.4 后停止工作,而 imagecreatefrompng() 和 imagecreatefromgif() 继续正常工作 - imagecreatefromjpeg() stopped working after upgrading to PHP 7.4 while imagecreatefrompng() and imagecreatefromgif() continue working properly 从4.1升级到MySQL 5.5后,Php-MySQL UPDATE&INSERT停止工作 - Php-MySQL UPDATE & INSERT stopped working after upgrading to MySQL 5.5 from 4.1 将我的网站升级到 PHP 8.0 后,PEAR send() 函数停止工作! 状态码 500 - After upgrading my website to PHP 8.0 PEAR send() function stopped working! Status code 500 升级到laravel 5.3后不进行分组 - Group by not working after upgrading to laravel 5.3 升级 Ubuntu 后,Php 无法在 Apache/2.4.52 上运行 - After upgrading Ubuntu, Php is not working on Apache/2.4.52 升级Joomla后PHP代码无法正常工作 - PHP Code Not working after Upgrading Joomla 升级PHP后MySQL无法在Mac Sierra上运行 - Mysql not working on mac Sierra after upgrading php 从laravel 4.2升级后,分页器无法在laravel 5.2中工作 - Paginator not working in laravel 5.2 after upgrading from laravel 4.2 更新PHP后我的Apache停止工作 - After Updating PHP my Apache Stopped working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM