37

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

Pezhvak
  • 9,633
  • 7
  • 29
  • 39

4 Answers4

42

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.

Pezhvak
  • 9,633
  • 7
  • 29
  • 39
  • I updated my composer.json file, but when I run the composer update command, I still get the "deprecated" error so it seems like a catch-22 as composer runs the "artisan clear-compiled" command at the start and this is already causing the errors! Any ideas? I'm also not quite sure what your step 3 means, do I have to go into libraries and check their composer.json files? – matthiku Feb 01 '21 at 16:50
  • I got it working by temporarily removing the ""pre-update-cmd" from composer json. I also had to upgrade laravel/socialite to "^5.1". Anyway, thanks for your help above! – matthiku Feb 01 '21 at 17:02
  • @matthiku I don't think doing what you did is good (removing pre-update-cmd) my step 3 is to update those dependencies in your composer.yml file – Pezhvak Feb 01 '21 at 17:19
  • After running `composer update` i got an error message `Killed`. I had to upgrade composer to version 2 to make it work. – adambg Feb 11 '21 at 09:53
  • Faker `1.9.1` throws an error in my case. Instead, I kept `"fzaninotto/faker": "~1.4"` and it works fine. – Mohamed Shahid Jun 09 '21 at 06:12
  • 1
    after updating composer.json: Problem 1 - laravel/framework[v5.7.0, ..., 5.7.x-dev] require php ^7.1.3 -> your php version (8.1.2) does not satisfy that requirement. – Palo Jan 19 '23 at 09:09
2

Check your php version in your virtual machine(xampp or server).

php --version

Is that version 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.

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()

Downgrade your php version to 7.4 and your Laravel app works like a charm!

0

I had similar issue. But I had already run brew update and brew cleanup before I noticed the issue. What I did:

  1. I noticed this error from 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

excel
  • 51
  • 1
  • 5
0

If you're using valet you should do the followings:

  1. Downgrade from php8+ to php7.4 valet isolate php@7.4
  2. Then run composer update using valet valet composer update