Declaration of Illuminate\Container\Container::get($id) must be compatible with Psr\Container\ContainerInterface::get(string $id) [duplicate]
Asked Answered
S

3

18

Installed new Laravel 8 project and upon loading the first instance, I get the below error. It's weird cause I put it aside and later on upgraded another project (which was working fine) from Laravel 5.8 -> 6 and got the similar error when I went to check the site out.

I've cleared the composer cache, deleted the vendor folder and reinstalled and can't seem to figure it out. Been racking my brain around this for the past day and it seems like some package version is incorrect but I'm not sure where to begin troubleshooting.

( ! ) Fatal error: Declaration of Illuminate\Container\Container::get($id) must be compatible with Psr\Container\ContainerInterface::get(string $id) in /home/vagrant/ps/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 15

Call Stack
#   Time    Memory  Function    Location
1   0.0001  357784  {main}( )   .../index.php:0
2   0.0133  502360  require_once( '/home/vagrant/ps/bootstrap/app.php' )    .../index.php:47
3   0.0133  502360  spl_autoload_call ( )   .../app.php:14
4   0.0133  502424  Composer\Autoload\ClassLoader->loadClass( ) .../app.php:14
5   0.0133  502424  Composer\Autoload\includeFile( )    .../ClassLoader.php:322
6   0.0135  578336  include( '/home/vagrant/ps/vendor/laravel/framework/src/Illuminate/Foundation/Application.php' )    .../ClassLoader.php:444
7   0.0135  578336  spl_autoload_call ( )   .../Application.php:29
8   0.0135  578392  Composer\Autoload\ClassLoader->loadClass( ) .../Application.php:29
9   0.0135  578392  Composer\Autoload\includeFile( )    .../ClassLoader.php:322
10  0.0138  588440  include( '/home/vagrant/ps/vendor/laravel/framework/src/Illuminate/Container/Container.php' )   .../ClassLoader.php:444
Spectre answered 8/3, 2021 at 8:13 Comment(0)
N
30

What version of PHP are you using? It looks like this problem's happening because of the static typing added to psr/container between v1.0.0 and v.1.1.0 released five days ago to deprecate PHP < 7.2

https://github.com/php-fig/container/blob/1.0.0/src/ContainerInterface.php#L23

https://github.com/php-fig/container/blob/1.1.0/src/ContainerInterface.php#L22

Pinning psr/container to v1.0.0 should resolve this until Illuminate is updated

Nesmith answered 10/3, 2021 at 11:52 Comment(7)
Thanks, that was exactly the problem. When I put phpinfo() to see what was outputted, it was using version 7.1.3 when my CLI version was on 7.4. Quick restart of the server after changing the config and it worked.Spectre
I've been trying to figure this one out for almost a week. Thank you so much for your answer here. plugged in "psr/container": "1.0.0" at the bottom of my composer.json, ran update, and then deployed and it works great now. Thank you so much for this answer @SpectreErivan
got the same error today, I'm not sure I understand the solution where do I plug in the "psr/container": "1.0.0" is it in the main composer.js at the root on "require:{}" or on "require-dev:{}"Mideast
@Mideast - yes, in the require section of the main composer.js should do the trick.Nesmith
When adding "psr/container": "1.0.0" in composer.json, I get this page isn't working http error 500Spatterdash
@Spatterdash I am getting the same error, http error 500. Did you solved this.?Esthonia
Hello @Spectre where exactly in composer.json file do you put that line. I have placed it at the bottom of composer.json file and ran composer update but still getting the same error. Please helpHeavyfooted
E
3

( ! ) Fatal error: Declaration of Illuminate\Container\Container::get($id) must be compatible with Psr\Container\ContainerInterface::get(string $id) in /home/vagrant/ps/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 15

In my case I was using composer 1.10 and upgraded to version 2.0. The composer will downgrade to version 1.0.0 of Psr\Container and if you need to go back to composer 1 use the command:

composer self-update --1

Exhalant answered 14/4, 2021 at 19:48 Comment(0)
W
-2

Not relating to Laravel.

In case you working with old php 7 version and getting this error after installing phpMyAdmin (or any other software) as me solution is to install one of the older version of phpMyAdmin. 4.4.15.10 worked for me.

Edit: would like to know disliking reason

Woodprint answered 10/7, 2022 at 8:8 Comment(2)
The question is specifically about a package in a Laravel project. This answer is not related, just because it has same error message. If you delete your negative score answer you'll get back the points you lost.Tuscarora
question title and error is not Laravel specific. when you google this error answer is pretty useful. it's not about points. if I meet this error again I can google and see my answer.Woodprint

© 2022 - 2024 — McMap. All rights reserved.