Declaration of Illuminate\Container\Container::get($id) must be compatible with Psr\Container\ContainerInterface::get(string $id)
You are staring at a fatal error that screams a fundamental incompatibility between two interfaces, yet the stack trace points deep into Laravel's core. The message is unambiguous: Illuminate\Container\Container::get($id) declares its parameter as $id (typically inferred as mixed or allowing anything), while the parent interface Psr\Container\ContainerInterface::get(string $id) strictly demands a string.
This specific error usually manifests after upgrading from Laravel 5 to Laravel 6 or 8. It is not an abstract logic bug within your application code; it is a versioning conflict between the framework and a third-party dependency, often stemming from outdated autoloading artifacts left behind in vendor/.
The Root Cause: Interface Evolution
To understand why this happens, you have to look at how PHP handles inheritance and interfaces. Laravel's Container class implements Psr\Container\ContainerInterface. In earlier versions of the framework, or when running alongside older packages, the type hint for the $id parameter might not have been strict about being a string.
However, modern implementations of Psr\Container\ContainerInterface (specifically version 1.0.x and above) enforce that the container identifier must be a string. If you install a package that was written for an older PHP version or an older iteration of Laravel where the type hint was loose, Composer might resolve dependencies in a way that leaves your vendor/autoload.php referencing an outdated stub or a mismatched class definition.
When you clear the cache and reinstall, if the dependency resolution graph isn't updated correctly, or if a package like illuminate/container is somehow pointing to a version that expects a different PSR implementation, PHP throws this fatal error immediately upon loading the container. The call stack confirms this: it fails right as Illuminate/Foundation/Application tries to initialize its internal container.
Why Standard Fixes Often Fail
The advice "clear composer cache and delete vendor" is standard, but in cases involving interface mismatches, simply running composer update might not be enough if a specific package version is pinned incorrectly or if a conflicting package forces an older PSR version into your environment.
You need to ensure that the psr/container package itself is at the latest compatible version. This package acts as the contract between frameworks and service providers. If your project has a dependency requiring an older version of this PSR implementation, Laravel 6/8 will refuse to load because its internal container signature no longer matches.
Check your composer.lock file. Look for the psr/container entry. It should be resolving to a version that aligns with the strict typing requirements introduced in recent PHP versions. If you see a version discrepancy, or if a dependency is explicitly requiring an older psr/container, you may need to update that specific package's requirement in your composer.json or accept the incompatibility as a blocker for that third-party library.
Resolving the Type Hint Mismatch
The error message specifically points to line 15 of /vendor/laravel/framework/src/Illuminate/Container/Container.php. While you might be tempted to edit the Laravel source code to add a string type hint to the method signature, this is rarely the correct path for framework dependencies. Modifying core files creates merge conflicts during updates and bypasses Composer's version management.
Instead, focus on the dependency graph. Run the following command to inspect your dependencies:
composer why psr/container
This will show you which packages depend on psr/container and what version they require. If a package requires an older version than what is installed, update that specific package or adjust its requirement in composer.json.
If the issue persists after ensuring all PSR interfaces are up to date, check for any custom service providers you might have registered. Sometimes, manually registering a container in an old way can trigger these signature checks differently than Laravel's auto-discovery. Ensure your config/app.php does not contain manual binding logic that assumes older interface signatures.
When to Consider Reinstalling the Framework
If you are moving from Laravel 5.8 to 6.x or 8.x and encounter this error repeatedly, it is highly likely that some legacy package in your vendor/ folder is simply incompatible with the new framework's strict typing standards. Some packages were not updated when PHP moved toward stricter type declarations.
In such scenarios, removing the offending package from your composer.json requires list might be necessary. Alternatively, if the package is critical and has no update, you may need to find a drop-in replacement that adheres to the current PSR specifications. The goal is to have every class in your autoload path respect the interface contract defined by Psr\Container\ContainerInterface.
Once the dependency versions align and the psr/container package reflects the strict string typing required by modern Laravel, the fatal error will vanish, and your application will boot successfully without needing to touch core framework files.