Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muazzamazaz's avatar

PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key)

I am getting following error in Laravel

PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::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 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1277

Composer:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2.5|^8.0",
        "ext-dom": "*",
        "ext-gd": "*",
        "ext-json": "*",
        "anhskohbo/no-captcha": "^3.2",
        "doctrine/dbal": "^2.10",
        "fideloper/proxy": "^4.0",
        "fruitcake/laravel-cors": "^2.0",
        "geoip2/geoip2": "^2.12",
        "io-developer/php-whois": "^4.1",
        "ivopetkov/html5-dom-document-php": "2.*",
        "laravel/framework": "^6.20.26",
        "laravel/tinker": "^2.5",
        "league/csv": "^9.7",
        "protonemedia/laravel-verify-new-email": "^1.1",
        "simplesoftwareio/simple-qrcode": "^4.2",
        "spatie/ssl-certificate": "^1.22",
        "stripe/stripe-php": "^7.83",
        "symfony/dom-crawler": "^5.3",
        "whichbrowser/parser": "^2.1"
    },
    "require-dev": {
        "filp/whoops": "^2.0",
        "fakerphp/faker": "^1.9.1",
        "kitloong/laravel-migrations-generator": "^4.3",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.5.8|^9.3.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

0 likes
45 replies
Sinnbeck's avatar

Delete the vendor directory and run try running composer update

6 likes
muazzamazaz's avatar

@Sinnbeck

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
Deprecation Notice: 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 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Container\Container.php:1231
Deprecation Notice: Return type of Illuminate\Container\Container::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Container\Container.php:1242
Deprecation Notice: Return type of Illuminate\Container\Container::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Container\Container.php:1254
Deprecation Notice: Return type of Illuminate\Container\Container::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Container\Container.php:1267
> @php artisan package:discover --ansi

PHP Fatal error:  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::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 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1277
Stack trace:
#0 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...', 'E:\xampp\htdocs...', 1277)
#1 E:\xampp\htdocs\project1\vendor\composer\ClassLoader.php(571): include('E:\xampp\htdocs...')
#2 E:\xampp\htdocs\project1\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('E:\xampp\htdocs...')
#3 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\helpers.php(109): Composer\Autoload\ClassLoader->loadClass('Illuminate\Supp...')
#4 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collect(Array)
#5 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illuminate\Foundation\PackageManifest->build()
#6 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest()
#7 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config('aliases')
#8 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases()
#9 E:\xampp\htdocs\phprank-120n\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(219): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap(Object(Illuminate\Foundation\Application))
#10 E:\xampp\htdocs\phprank-120n\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith(Array)
#11 E:\xampp\htdocs\phprank-120n\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap()
#12 E:\xampp\htdocs\phprank-120n\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 {main} in E:\xampp\htdocs\phprank-120n\vendor\laravel\framework\src\Illuminate\Support\Collection.php on line 11
In Collection.php line 11:

  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExi
  sts($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWill
  Change] attribute should be used to temporarily suppress the notice in E:\xampp\htdocs\project1\vendor\laravel\
  framework\src\Illuminate\Support\Collection.php:1277
  Stack trace:
  #0 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Foun
  dation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...', 'E:\xampp\htdocs...', 1277)
  #1 E:\xampp\htdocs\project1\vendor\composer\ClassLoader.php(571): include('E:\xampp\htdocs...')
  #2 E:\xampp\htdocs\project1\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('E:\xampp\htd
  ocs...')
  #3 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\helpers.php(109): Composer\Autoload
  \ClassLoader->loadClass('Illuminate\Supp...')
  #4 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collec
  t(Array)
  #5 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illumi
  nate\Foundation\PackageManifest->build()
  #6 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illumin
  ate\Foundation\PackageManifest->getManifest()
  #7 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illumin
  ate\Foundation\PackageManifest->config('aliases')
  #8 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26
  ): Illuminate\Foundation\PackageManifest->aliases()
  #9 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(219): Illuminate
  \Foundation\Bootstrap\RegisterFacades->bootstrap(Object(Illuminate\Foundation\Application))
  #10 E:\xampp\htdocs\phprank-120n\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(320): Illumi
  nate\Foundation\Application->bootstrapWith(Array)
  #11 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illumi
  nate\Foundation\Console\Kernel->bootstrap()
  #12 E:\xampp\htdocs\project1\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component
  \Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
  #13 {main}


Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

I have got above when run composer update after successfully downloading files but at the end it shows

muazzamazaz's avatar
PHP Fatal error:  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::off
setExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illumin
ate\Support\Collection.php:1277
Stack trace:
#0 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...', 'E
:\xampp\htdocs...', 1277)
#1 E:\xampp\htdocs\project1\vendor\composer\ClassLoader.php(571): include('E:\xampp\htdocs...')
#2 E:\xampp\htdocs\project1\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('E:\xampp\htdocs...')
#3 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\helpers.php(109): Composer\Autoload\ClassLoader->loadClass('Illuminate\Supp...')
#4 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collect(Array)
#5 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illuminate\Foundation\PackageManifest->build()
#6 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest()
#7 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config('aliases')
#8 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases()
#9 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(219): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap(Object(Illuminate\Foundation
\Application))
#10 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith(Array)
#11 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap()
#12 E:\xampp\htdocs\project1\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOut
put))
#13 {main} in E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\Collection.php on line 11

In Collection.php line 11:

  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mix
  ed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Supp
  ort\Collection.php:1277
  Stack trace:
  #0 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...
  ', 'E:\xampp\htdocs...', 1277)
  #1 E:\xampp\htdocs\project1\vendor\composer\ClassLoader.php(571): include('E:\xampp\htdocs...')
  #2 E:\xampp\htdocs\project1\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('E:\xampp\htdocs...')
  #3 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Support\helpers.php(109): Composer\Autoload\ClassLoader->loadClass('Illuminate\Supp...')
  #4 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collect(Array)
  #5 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illuminate\Foundation\PackageManifest->build()
  #6 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest()
  #7 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config('aliases')
  #8 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases()
  #9 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(219): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap(Object(Illuminate\Found
  ation\Application))
  #10 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith(Array)
  #11 E:\xampp\htdocs\project1\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap()
  #12 E:\xampp\htdocs\project1\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\Conso
  leOutput))
  #13 {main}

no success even self update won't help

Sinnbeck's avatar

@muazzamazaz Ok. I dont know how to update composer on windows :) There is probably a guide somewhere

muazzamazaz's avatar

$ composer self-update You are already using the latest available Composer version 2.2.7 (stable channel).

MarkJC's avatar

@Sinnbeck May I ask you a question. I was having similar problems of composer not being able to update. I.e. Error "Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement" You referred us to this link: https://github.com/laravel/framework/blob/6.x/composer.json#L18 I copied your setup and banged it into my composer.json and it now works. Can you explain what this did. Did it put in correct files that were missing. Apol. Newbie.

muazzamazaz's avatar

I have tried it running using PHP 7.4 or upgrading to Laravel 7 at PHP 8.1 but still getting errors:

PHP Fatal error:  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::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 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1277
Stack trace:
#0 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...', 'C:\xampp\htdocs...', 1277)
#1 C:\xampp\htdocs\phpranking\vendor\composer\ClassLoader.php(571): include('C:\xampp\htdocs...')
#2 C:\xampp\htdocs\phpranking\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('C:\xampp\htdocs...')
#3 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Support\helpers.php(109): Composer\Autoload\ClassLoader->loadClass('Illuminate\Supp...')
#4 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collect(Array)
#5 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illuminate\Foundation\PackageManifest->build()
#6 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest()
#7 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config('aliases')
#8 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases()
#9 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(219): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap(Object(Illuminate\Foundation\Application))
#10 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith(Array)
#11 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap()
#12 C:\xampp\htdocs\phpranking\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 {main} in C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Support\Collection.php on line 11
In Collection.php line 11:

  During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExi
  sts($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWill
  Change] attribute should be used to temporarily suppress the notice in C:\xampp\htdocs\phpranking\vendor\laravel\fr
  amework\src\Illuminate\Support\Collection.php:1277
  Stack trace:
  #0 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Founda
  tion\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...', 'C:\xampp\htdocs...', 1277)
  #1 C:\xampp\htdocs\phpranking\vendor\composer\ClassLoader.php(571): include('C:\xampp\htdocs...')
  #2 C:\xampp\htdocs\phpranking\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('C:\xampp\htdoc
  s...')
  #3 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Support\helpers.php(109): Composer\Autoload\C
  lassLoader->loadClass('Illuminate\Supp...')
  #4 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collect(
  Array)
  #5 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illumina
  te\Foundation\PackageManifest->build()
  #6 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illuminat
  e\Foundation\PackageManifest->getManifest()
  #7 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminat
  e\Foundation\PackageManifest->config('aliases')
  #8 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26):
   Illuminate\Foundation\PackageManifest->aliases()
  #9 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(219): Illuminate\F
  oundation\Bootstrap\RegisterFacades->bootstrap(Object(Illuminate\Foundation\Application))
  #10 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(320): Illumina
  te\Foundation\Application->bootstrapWith(Array)
  #11 C:\xampp\htdocs\phpranking\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illumina
  te\Foundation\Console\Kernel->bootstrap()
  #12 C:\xampp\htdocs\phpranking\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\C
  onsole\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
  #13 {main}


Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

2 likes
Evaristo's avatar

@muazzamazaz I'm having the same error .. . Everything you said around this post it's happening with me. So, how did you fix it?

EltonVilanculo's avatar

@Evaristo , this is php version issue, you probably have some composer dependencies that doesn’t work properly in new php version so you need to :

  1. Delete vendor directory
  2. downgrade you php version (I suggest 7.4) 3.Run "composer update"
1 like
rodinmehr's avatar

I had the same problem. I switched back to PHP 7.4 and ran composer update and everything worked smoothly! To switch between PHP versions: $sudo update-alternatives --config php

select the one that you want (here 7.4 works), If you're using nginx: $sudo service nginx restart $sudo service php7.4-fpm restart $sudo service php8.1-fpm restart

Now run: $composer update It should work fine!

After I updated Laravel to 7 from 6, I again updated from Laravel 7 to 8 (using upgrade guide from Laravel documentation). After this I again switched back to PHP 8.1 and then ran composer update again and everything was fine!

4 likes
masoodanwar85's avatar

I did the following and it worked fine:

-- Open composer.json file and change php version to something like this: "php": "^7.3|^8.1"

-- Then run composer update

Hope that help

5 likes
akLearn's avatar

@masoodanwar85 Thanks bro. This helped me too.

Don't understand why this worked though. Do you?

I had pulled in a package and it worked fine while being in a docker environment. Then one day it stopped working and then your solution fixed it. Curious what the reason is.

Daniel_cok's avatar

Please, @muazzamazaz @sinnbeck @rodinmehr still the problem. If I write composer update I have the same problem as when I use php artisan ...

php artisan PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::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 C:\Frontend\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1349 Stack trace: #0 C:\Frontend\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() #1 C:\Frontend\vendor\composer\ClassLoader.php(571): include('...') #2 C:\Frontend\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile() #3 C:\Frontend\vendor\laravel\framework\src\Illuminate\Support\helpers.php(110): Composer\Autoload\ClassLoader->loadClass() #4 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collect() #5 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illuminate\Foundation\PackageManifest->build() #6 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest() #7 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config() #8 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases() #9 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(230): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap() #10 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith() #11 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(127): Illuminate\Foundation\Console\Kernel->bootstrap() #12 C:\Frontend\artisan(37): Illuminate\Foundation\Console\Kernel->handle() #13 {main} in C:\Frontend\vendor\laravel\framework\src\Illuminate\Support\Collection.php on line 11

In Collection.php line 11:

During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute shoul d be used to temporarily suppress the notice in C:\Frontend\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1349 Stack trace: #0 C:\Frontend\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() #1 C:\Frontend\vendor\composer\ClassLoader.php(571): include('...') #2 C:\Frontend\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile() #3 C:\Frontend\vendor\laravel\framework\src\Illuminate\Support\helpers.php(110): Composer\Autoload\ClassLoader->loadClass() #4 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collect() #5 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illuminate\Foundation\PackageManifest->build() #6 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest() #7 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config() #8 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases() #9 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(230): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap() #10 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(310): Illuminate\Foundation\Application->bootstrapWith() #11 C:\Frontend\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(127): Illuminate\Foundation\Console\Kernel->bootstrap() #12 C:\Frontend\artisan(37): Illuminate\Foundation\Console\Kernel->handle() #13 {main}

rokefeler's avatar

from: masoodanwar85 -- Open composer.json file and change php version to something like this: "php": "^7.3|^8.1" -- upgrade composer (important) -- Then run composer update

LaraBABA's avatar

I believe this happened to you because you opened PHPStorm while your local server was let's say on PHP8.1, you then changed the version of your PHP server to 7.4 and hoped PHP storm would pick on it, but it does not.

What I do in this case is always set the server to the right PHP version and then open PHP storm(if you use such IDE).

Always make sure that PHP storms points to the correct PHP paths or your console will struggle finding the set PHP.

vector_rashed's avatar

My case was PHP version issue. I changed PHP version 8.* to 7.4. Laravel version

1 like
Osahady's avatar

I have the same problem but not resolved. I have an old project of laravel 3 years ago ... first it asks for php version to be 7.4 but the one I have is 8.1.6 -------> solved but composer insall refuses to complete with the following error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Sup port\Collection::offsetExists($key) should either be compatible with ArrayAccess::offsetE xists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to t emporarily suppress the notice in D:\05_web\projects\Accounting-System\vendor\laravel\fra mework\src\Illuminate\Support\Collection.php:1277 Stack trace: #0 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Support\C ollection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'R eturn type of ...', 'D:\05_web\proje...', 1277) #1 D:\05_web\projects\Accounting-System\vendor\composer\ClassLoader.php(571): include('D: \05_web\proje...') #2 D:\05_web\projects\Accounting-System\vendor\composer\ClassLoader.php(428): Composer\Au toload\includeFile('D:\05_web\proje...') #3 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Support\h elpers.php(109): Composer\Autoload\ClassLoader->loadClass('Illuminate\Supp...') #4 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundatio n\PackageManifest.php(130): collect(Array) #5 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundatio n\PackageManifest.php(106): Illuminate\Foundation\PackageManifest->build() #6 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundatio n\PackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest() #7 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundatio n\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config('aliases') #8 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundatio n\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases() #9 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundatio n\Application.php(219): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap(Object (Illuminate\Foundation\Application)) #10 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundati on\Console\Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith(Array) #11 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundati on\Console\Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap() #12 D:\05_web\projects\Accounting-System\artisan(37): Illuminate\Foundation\Console\Kerne l->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Con sole\Output\ConsoleOutput)) #13 {main}

PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::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 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1277 Stack trace: #0 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Support\Collection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...', 'D:\05_web\proje...', 1277) #1 D:\05_web\projects\Accounting-System\vendor\composer\ClassLoader.php(571): include('D:\05_web\proje...') #2 D:\05_web\projects\Accounting-System\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('D:\05_web\proje...') #3 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Support\helpers.php(109): Composer\Autoload\ClassLoader->loadClass('Illuminate\Supp...') #4 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(130): collect(Array) #5 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(106): Illuminate\Foundation\PackageManifest->build() #6 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest() #7 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundation\PackageManifest.php(78): Illuminate\Foundation\PackageManifest->config('aliases') #8 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->aliases() #9 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(219): Illuminate\Foundation\Bootstrap\RegisterFacades->bootstrap(Object(Illuminate\Foundation\Application)) #10 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith(Array) #11 D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap() #12 D:\05_web\projects\Accounting-System\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #13 {main} in D:\05_web\projects\Accounting-System\vendor\laravel\framework\src\Illuminate\Support\Collection.php on line 11 Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255

priyalaks's avatar

PHP Version issue causes this . To check your PHP version . Try to refresh your environment variable from your command line and try once again.

refreshenv

Faddy's avatar

I got the same issue after moving my project from a local Xampp with PHP 8.0.* to an IIS server where I had PHP 8.1.*. Switching it from PHP 8.1 to 8.0 solved it for me. Ensure you change the PHP paths EVERYWHERE necessary - in environment variables, FastCGI settings, Project path etc.

laracboy1's avatar

First install php version PHP 8.1 then in compose.json

{ "require": { "php": "^7.2.5|^8.0.13", ... "laravel/framework": "^8", }, config:{ "platform": { "php":"7.4" } } }

then run composer install

M0o0hamedAhmed's avatar

in the beginning I had some error so I can`t make migrate or any thing I had som problem so I changed php version from 8.1 to 7.4 then migration is done but when run php artisan serve show some error in broswer

During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::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 C:\laragon\www\halaky-web-api\vendor\laravel\framework\src\Illuminate\Support\Collection.php:1277 ◀ Stack trace:

ufak's avatar

@M0o0hamedAhmed I'm also having something similar to this:

[Sat Jan 13 01:22:05.524578 2024] [php:error] [pid 7100:tid 1840] [client ::1:49688] PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of Illuminate\Support\Collection::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 C:\xampp\htdocs\fleetcart\vendor\laravel\framework\src\Illuminate\Collections\Collection.php:1459\nStack trace:\n#0 C:\xampp\htdocs\fleetcart\vendor\laravel\framework\src\Illuminate\Collections\Collection.php(13): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8192, 'Return type of ...', 'C:\\xampp\\htdocs...', 1459)\n#1 C:\xampp\htdocs\fleetcart\vendor\composer\ClassLoader.php(571): include('C:\\xampp\\htdocs...')\n#2 C:\xampp\htdocs\fleetcart\vendor\composer\ClassLoader.php(428): Composer\Autoload\includeFile('C:\\xampp\\htdocs...')\n#3 C:\xamp

I'm using xampp with php version 8.2.4 on windows, please any help?

Gizmo440's avatar

@LaraCoder7 I added this to my composer.json and it got rid of all those same errors but now this error pops up?

Illuminate\Foundation\ComposerScripts::postAutoloadDump @php artisan package:discover --ansi

In trustedproxy.php line 42:

Undefined constant Illuminate\Http\Request::HEADER_X_FORWARDED_ALL

gkohli's avatar

composer self-update , delete vender and composer install worked for me.

idhamhafidz's avatar

I got this error whilre running my web app ( using laravel with php7.3 ) using homestead. It took me so long to finally found out that the error I got was from running php8 in the host machine.

So I change the php version from the host machine to 7.3 as well.

Now the problem has all gone.

I dont know why but apparently, the php in the host machine does affect the php in the homesteead as well.

So you need to make sure the php version in homestead is the same as the host machine.

1 like
jd-ashish's avatar

In composer.json file in script object define PHP version like @php7.4

"scripts": { "post-root-package-install": [ "@php7.4 -r "file_exists('.env') || copy('.env.example', '.env');"" ], "post-create-project-cmd": [ "@php7.4 artisan key:generate --ansi" ], "post-autoload-dump": [ "Illuminate\Foundation\ComposerScripts::postAutoloadDump", "@php7.4 artisan package:discover --ansi" ] },

Please or to participate in this conversation.