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

zigma's avatar
Level 1

problem running laravel 7 code after update php7 to php 8

My code is in Laravel framework 7 and I used php ver 7 before. I recently just updated my apache and php to latest version: apache 2.4.54 php 8.1.8

when I try to view my laravel page it gives me the following error:

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 D:\www\heymart\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 1271

Deprecated: 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 D:\www\heymart\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 1282

Deprecated: 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 D:\www\heymart\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 1294

Deprecated: 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 D:\www\heymart\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 1307

Deprecated: Return type of Illuminate\Routing\AbstractRouteCollection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php on line 245

Deprecated: Return type of Illuminate\Routing\AbstractRouteCollection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php on line 235

Deprecated: Return type of Symfony\Component\HttpFoundation\ParameterBag::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\http-foundation\ParameterBag.php on line 205

Deprecated: Return type of Symfony\Component\HttpFoundation\ParameterBag::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\http-foundation\ParameterBag.php on line 215

Deprecated: Return type of Symfony\Component\HttpFoundation\HeaderBag::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\http-foundation\HeaderBag.php on line 255

Deprecated: Return type of Symfony\Component\HttpFoundation\HeaderBag::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\http-foundation\HeaderBag.php on line 265

Deprecated: Return type of Illuminate\Http\Request::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\laravel\framework\src\Illuminate\Http\Request.php on line 637

Deprecated: Return type of Illuminate\Http\Request::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\laravel\framework\src\Illuminate\Http\Request.php on line 651

Deprecated: Return type of Illuminate\Http\Request::offsetSet($offset, $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 D:\www\heymart\vendor\laravel\framework\src\Illuminate\Http\Request.php on line 663

Deprecated: Return type of Illuminate\Http\Request::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\laravel\framework\src\Illuminate\Http\Request.php on line 674

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in D:\www\heymart\vendor\symfony\http-foundation\Request.php on line 303

Deprecated: mb_strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in D:\www\heymart\vendor\laravel\framework\src\Illuminate\Support\Str.php on line 177

Deprecated: mb_strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in D:\www\heymart\vendor\laravel\framework\src\Illuminate\Support\Str.php on line 177

Deprecated: Return type of Dotenv\Repository\AbstractRepository::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\vlucas\phpdotenv\src\Repository\AbstractRepository.php on line 147

Deprecated: Return type of Dotenv\Repository\AbstractRepository::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\vlucas\phpdotenv\src\Repository\AbstractRepository.php on line 155

Deprecated: Return type of Dotenv\Repository\AbstractRepository::offsetSet($offset, $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 D:\www\heymart\vendor\vlucas\phpdotenv\src\Repository\AbstractRepository.php on line 163

Deprecated: Return type of Dotenv\Repository\AbstractRepository::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\vlucas\phpdotenv\src\Repository\AbstractRepository.php on line 171

Deprecated: Return type of PhpOption\None::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\phpoption\phpoption\src\PhpOption\None.php on line 118

Deprecated: Return type of PhpOption\Some::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\phpoption\phpoption\src\PhpOption\Some.php on line 152

Deprecated: Return type of Illuminate\Config\Repository::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:\www\heymart\vendor\laravel\framework\src\Illuminate\Config\Repository.php on line 141

Deprecated: Return type of Illuminate\Config\Repository::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 D:\www\heymart\vendor\laravel\framework\src\Illuminate\Config\Repository.php on line 152

Deprecated: Return type of Illuminate\Config\Repository::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 D:\www\heymart\vendor\laravel\framework\src\Illuminate\Config\Repository.php on line 164

Deprecated: Return type of Illuminate\Config\Repository::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 D:\www\heymart\vendor\laravel\framework\src\Illuminate\Config\Repository.php on line 175

Deprecated: Return type of Symfony\Component\Finder\Finder::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Finder.php on line 607

Deprecated: Return type of Symfony\Component\Finder\Finder::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Finder.php on line 676

Deprecated: Return type of Symfony\Component\Finder\Iterator\FileTypeFilterIterator::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\FileTypeFilterIterator.php on line 42

Deprecated: Return type of Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator::getChildren() should either be compatible with RecursiveDirectoryIterator::getChildren(): RecursiveDirectoryIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\RecursiveDirectoryIterator.php on line 85

Deprecated: Return type of Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator::rewind() should either be compatible with FilesystemIterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\RecursiveDirectoryIterator.php on line 113

Deprecated: Return type of Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator::current() should either be compatible with FilesystemIterator::current(): SplFileInfo|FilesystemIterator|string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\RecursiveDirectoryIterator.php on line 61

Deprecated: Return type of Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\ExcludeDirectoryFilterIterator.php on line 55

Deprecated: Return type of Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::hasChildren() should either be compatible with RecursiveIterator::hasChildren(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\ExcludeDirectoryFilterIterator.php on line 74

Deprecated: Return type of Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator::getChildren() should either be compatible with RecursiveIterator::getChildren(): ?RecursiveIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\ExcludeDirectoryFilterIterator.php on line 79

Deprecated: Return type of Symfony\Component\Finder\Iterator\FilenameFilterIterator::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\FilenameFilterIterator.php on line 28

Deprecated: Return type of Symfony\Component\Finder\Iterator\PathFilterIterator::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:\www\heymart\vendor\symfony\finder\Iterator\PathFilterIterator.php on line 27

looks like my laravel code use Deprecated function. Can anyone help me with the proper way to fix this issue?

Best regards Zigma

0 likes
12 replies
Akash_kushwaha's avatar

Laravel 7 doesn't support php 8.1 you have to change back your php version to 7.

2 likes
sos99's avatar

Hi @zigma

you can get the answer by looking at Laravel 9 upgrade page

https://laravel.com/docs/9.x/upgrade#php-return-types

PHP Return Types

PHP is beginning to transition to requiring return type definitions on PHP methods such as offsetGet, offsetSet, etc. In light of this, Laravel 9 has implemented these return types in its code base. Typically, this should not affect user written code; however, if you are overriding one of these methods by extending Laravel's core classes, you will need to add these return types to your own application

as @akash_kushwaha wrote you can upgrade from 7 to Laravel 9 (it is not soo complicated)

to work with Laravel and PHP 8.1

also, you can work with Laravel shift to make it faster - personally, I didn't use this service, I did it by myself with static analysis and Laravel docs (really, is not as hard as you think)

1 like
zigma's avatar
Level 1

so I try edit the composer.json, and run composer update.

it gives me the following error:

D:\www\heymart>composer update
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - illuminate/support[v7.0.0, ..., v7.28.4] require php ^7.2.5 -> your php version (8.1.8) does not satisfy that requirement.
    - Only one of these can be installed: illuminate/support[dev-master, v5.0.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, .
.., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev], laravel/framework[v9.0.0-beta.1, ..., 9.x-dev]. laravel/framework replaces illuminate/support and thus cann
ot coexist with it.
    - milon/barcode[7.0.0, ..., 7.0.1] require illuminate/support ^7.0 -> satisfiable by illuminate/support[v7.0.0, ..., 7.x-dev].
    - Root composer.json requires milon/barcode ^7.0 -> satisfiable by milon/barcode[7.0.0, 7.0.1].
    - Root composer.json requires laravel/framework ^9.0 -> satisfiable by laravel/framework[v9.0.0-beta.1, ..., 9.x-dev].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

D:\www\heymart>

can anyone help? best regards Zigma

Sinnbeck's avatar

@zigma not sure why, but seems laravel 7 does not work with 8.x even though the composer.json claims it does, so @akash_kushwaha is correct.

Update to laravel 8

3 likes
azs06's avatar

Was facing this issue when tried with PHP 8, downgraded to PHP 7 and ran composer update and the issue was solved.

1 like
Snapey's avatar

just make sure you clear views and cache

1 like
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.

Please or to participate in this conversation.