Php – Declaration of Illuminate\Container\Container::get($id) must be compatible with Psr\Container\ContainerInterface::get(string $id)

laravelPHPvagrant

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

Best Answer

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

Related Topic