close

[Solved] PHP Deprecated: Return type of while using artisan command

I am trying to run my PHP artisan command And I am facing PHP Deprecated error: PHP Deprecated: Return type of while using artisan command in laravel. In this Exerror article, We are going to learn about How to reproduce this error and we will discuss All Possible Solutions Lets Get Start with This Article.

How PHP Deprecated: Return type of while using artisan command Error Occurs?

I am trying to run my PHP artisan command And I am facing PHP Deprecated error.

PHP Deprecated: Return type of Illuminate\Container\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1231

Deprecated: Return type of Illuminate\Container\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/jakefeeley/Sites/certhub/marketing/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1231

So here I am writing all the possible solutions that I have tried to resolve this error.

How To Solve PHP Deprecated: Return type of while using artisan command Error?

  1. How To Solve PHP Deprecated: Return type of while using artisan command Error?

    To Solve PHP Deprecated: Return type of while using artisan command Error If You have the latest PHP version installed then update your project’s PHP version to the latest version to 8.1 or whichever latest PHP version is installed in your system. Open your composer.json and change this PHP version: “php”: “^7.2|^8.1” And now, run the composer update command: composer update And now, You can run the PHP artisan command without any error and now your error will be solved.

  2. PHP Deprecated: Return type of while using artisan command

    To Solve PHP Deprecated: Return type of while using artisan command Error You need to change “laravel/framework”: “^8.75” in Your composer.json file. And then composer update will solve this error. First of all Open your composer.json and find laravel/framework under require section and change its version to 8.75. Just like this: “laravel/framework”: “^8.75” And now, run the composer update command: composer update And now, You can run the PHP artisan command without any error and now your error will be solved.

Solution 1: Change Laravel Version

To Solve PHP Deprecated: Return type of while using artisan command Error You need to change “laravel/framework”: “^8.75” in Your composer.json file. And then composer update will solve this error.

First of all Open your composer.json and find laravel/framework under require section and change its version to 8.75. Just like this.

{
    "name": "laravel/laravel",
    "type": "project",
    .......
    .......
    "require": {
        .......
        .......
        "laravel/framework": "^8.75",
        .......
        .......
    },
}

And now, run the composer update command.

composer update

And now, You can run the PHP artisan command without any error and now your error will be solved.

Solution 2: Change PHP Version

If You have the latest PHP version installed then update your project’s PHP version to the latest version to 8.1 or whichever latest PHP version is installed in your system. Open your composer.json and change this PHP version.

{
    "name": "laravel/laravel",
    "type": "project",
    .......
    .......
    "require": {
       "php": "^7.2|^8.1",
        .......
        .......
    },
}

And now, run the composer update command.

composer update

And now, You can run the PHP artisan command without any error and now your error will be solved.

Conclusion

It’s all About this error. I hope We Have solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

2 thoughts on “[Solved] PHP Deprecated: Return type of while using artisan command”

Leave a Comment