15

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
cLin
  • 334
  • 1
  • 2
  • 7

3 Answers3

28

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

SEYED BABAK ASHRAFI
  • 4,093
  • 4
  • 22
  • 32
Nev Stokes
  • 9,051
  • 5
  • 42
  • 44
  • 2
    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. – cLin Mar 14 '21 at 22:28
  • 4
    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 @cLin – Kevin Foster Mar 16 '21 at 00:25
  • 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:{}" – Wells Apr 22 '21 at 11:34
  • @Wells - yes, in the `require` section of the main `composer.js` should do the trick. – Nev Stokes Apr 23 '21 at 12:24
  • When adding "psr/container": "1.0.0" in composer.json, I get this page isn't working http error 500 – sd077 Apr 26 '21 at 05:41
  • @sd077 I am getting the same error, http error 500. Did you solved this.? – Jay Momaya Jun 04 '21 at 16:23
  • Hello @cLin 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 help – Fokwa Best Jul 02 '22 at 15:59
2

( ! ) 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

baikho
  • 5,203
  • 4
  • 40
  • 47
-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

Hebe
  • 661
  • 1
  • 7
  • 13
  • 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. – miken32 Apr 07 '23 at 00:35
  • 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. – Hebe Apr 07 '23 at 13:24