Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel app stopped working after upgrading to php 8

Tags:

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

like image 581
Pezhvak Avatar asked Dec 09 '20 14:12

Pezhvak


People also ask

Is Laravel ready for PHP 8?

PHP 8 has been officially released! We've been hard at work behind the scenes to provide support for all our libraries so that upgrading to PHP 8 with Laravel is easy. First, make sure you're at the latest version of Laravel 6, 7 or 8 to get PHP 8 support.

Does Laravel 8 require PHP 8?

Laravel 8 requires PHP 7.3+ or above so you need this version or the latest version of PHP installed on your system.

Which PHP version is best for Laravel?

PHP 8.0 is the undisputed champion with Laravel, while PHP 8.1 came in last.

Can Laravel 6 be upgraded to 8?

2 Answers. Show activity on this post. If you meant to upgrade your current Laravel 4.2 project to 8.0, you need to upgrade to 5(5.0 - 5.8) first, then 6, then 7, and then 8.


1 Answers

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:

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- to run composer update to update your laravel to the latest version

composer update 

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- 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.

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.

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

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

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

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

like image 196
Pezhvak Avatar answered Oct 17 '22 09:10

Pezhvak