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
PSR-11: Container interface This document describes a common interface for dependency injection containers. The goal set by ContainerInterface is to standardize how frameworks and libraries make use of a container to obtain objects and parameters (called entries in the rest of this document).
Users SHOULD NOT pass a container into an object so that the object can retrieve its own dependencies . This means the container is used as a Service Locator which is a pattern that is generally discouraged. Please refer to section 4 of the META document for more details. 2. Package
This document describes a common interface for dependency injection containers. The goal set by ContainerInterface is to standardize how frameworks and libraries make use of a container to obtain objects and parameters (called entries in the rest of this document).
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
( ! ) 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With