1

I'm having some troubles when i run my laravel project. Every time I try to login or register a new user i get this error: at HandleExceptions->handleError('8192', 'Method ReflectionParameter::getClass() is deprecated', 'C:\xampp\htdocs\project\vendor\laravel\framework\src\Illuminate\Routing\Route.php', '287') in Route.php line 287

I've already tried to update some values on my composer.json file and then running the composer update command like it says on this thread but still doesn't work.

My composer.json file is:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": "^7.3|^8.0",
    "laravel/framework": "^8.54",
    "barryvdh/laravel-ide-helper": "^2.2",
    "laravelcollective/html": "5.2.*",
    "kartik-v/bootstrap-fileinput": "@dev",
    "laracasts/flash": "^2.0",
    "cohensive/embed": "dev-master",
    "chumper/zipper": "0.6.x"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "^9.0",
    "symfony/css-selector": "2.8.*|3.0.*",
    "symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ]
},
"config": {
    "preferred-install": "dist"
}

}

Thanks if you can help me.

jupachon
  • 13
  • 1
  • 4

1 Answers1

1

PROBLEM EXPLANATION

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.

Solution

Solution for this problem is to downgrade or use two php versions for your project. Here are the following changes you need to make in your project.

  1. Add php 7.* version in your project by updating composer.json file. Just add the following line of code in your composer.json file.

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

2- Now run composer update

3-Make sure all other php dependable libraries version. Because some libraries support php 8 and some supports php 7 so we need them to downgrade as we downgraded our php version.

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

4- Thats all you need to do.

Zain Ali
  • 221
  • 2
  • 6
  • I've already tried this without success. Every time I try to run composer update I get the same error. – jupachon Sep 14 '21 at 15:43