Laravel App Stopped Working After Upgrading to PHP 8

Laravel app stopped working after upgrading to php 8

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.

Laravel issue after upgrade host to php 8.1

I resolve the problem with the upgrade laravel from 7 to 8

ReflectionParameter::getClass() method deprecated in php 8.0.1

You can replace it with getType(), which the documentation suggest. You have to create your own ReflectionClass, from the ReflectionType. This should do the trick.

$reflectionClass = new ReflectionClass($reflectionParam->getType()->getName());

I have this sandbox, that helped me assure it was working as intended.

How to fix laravel/ui error to upgrade Laravel after upgrading PHP to 8.0

As written in these multiple lines of errors: you are using outdated packages that are not yet compatible with PHP 8, nor with each other.

You require laravel/ui in v2 which does only support Laravel v7, along with laravel/framework which is the core of Laravel v8. Either update laravel/ui to v3, or downgrade Laravel to v7. This problem does not related to PHP8 from my point of view - it's a miracle that you haven't had any problems before



Related Topics



Leave a reply



Submit