Home > Software design >  Laravel 9 is getting "PHP Fatal error: Uncaught ErrorException: Method ReflectionParameter::get
Laravel 9 is getting "PHP Fatal error: Uncaught ErrorException: Method ReflectionParameter::get

Time:01-28

I build an aplication in Laravel 9 using Laravel Breeze and also vite. There is no problem with my application on my localhost (PHP 8.2). Problem stars when I try to deploy the application on server, I did everything normally according to Laravel Deployment documentation, but I am still getting this error from log on server: PHP Fatal error: Uncaught ErrorException: Method ReflectionParameter::getClass() is deprecated in and after this there is an list of files where this method is used I assume.

I googled this error, but every answer about this problem is only when someone was upgrading older project to PHP 8.0 or higher.

Here is also my composer file and I think I got everything in order:

`{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0.2",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.19",
        "laravel/sanctum": "^3.0",
        "laravel/tinker": "^2.7",
        "livewire/livewire": "^2.10",
        "nesbot/carbon": "^2.64"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/breeze": "^1.15",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.5.10",
        "spatie/laravel-ignition": "^1.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}`

Thanks.

I tried everything, including composer update and I double-checked my deployment method, which I am using for every project.

CodePudding user response:

It is usually caused by a compatibility issue between the version of PHP on your server and the version of Laravel and its dependencies that you are using.

The ReflectionParameter::getClass() method has been deprecated in PHP 8.0 and removed in PHP 8.2.

To resolve this issue, you may need to update your application to a version of Laravel that is compatible with PHP 8.2 and its dependencies.

Additionally, you can try downgrading the PHP version on your server to a version that is supported by your application, or upgrading your application to a version that is compatible with the PHP version on your server.

It seems like in your local you are having PHP version less than 8.2 and in your server it is 8.2. You can check it by adding the following code to a route or controller in your Laravel application:

<?php

phpinfo();

CodePudding user response:

Sorry guys, mistake was on my end :). I have two project (old one from 2017 and this new one) on one server. I just set root directory on this new domain to old version of project. :)

  • Related