skip to Main Content

NB: Local server PHP Version 8.1.4, laravel project inside composer.json file have "php": "^7.2.5", version & "laravel/framework": "^7.0"

PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of IlluminateSupportCollection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

error displaying below like this :

5

Answers


  1. You would need to upgrade your Laravel Framework version to at least version 8 and it’s dependencies using composer.

    Reference: https://laravel.com/docs/8.x/releases

    Or if you want to postpone it, you would need to add #[ReturnTypeWillChange] before declaring every function that throws the error. This is highly not advisable.

    P.S. If you updated your PHP version you would have to change the PHP version in composer to the one used, in your case it should be "php": "^8.1.4"

    Login or Signup to reply.
  2. That’s a php version issue. Upgrade laravel or downgrade PHP. This article covers how to downgrade the PHP version so it matches the Laravel Version.

    https://bytexd.com/fix-laravel-return-type-of-illuminatesupportcollectionoffsetexistskey/

    Login or Signup to reply.
  3. run "composer update" on your project directory and it will work .

    Login or Signup to reply.
  4. in your composer.json update line

    "php": "^7.3",
    

    to

    "php": "^7.3|^8.1",
    

    and run composer update

    Login or Signup to reply.
  5. In my case, using a mac, turns out my php version was 8.1 which somehow is not compatible with laravel version 7. Tho most of these answers are correct, but they did not fix my issues. I followed these steps (if brew is installed):

    1. brew unlink [email protected]
    2. brew link [email protected] or lower

    Reference How can I easily switch between PHP versions on Mac OSX?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search