Description
Symfony version(s) affected
<6.0.0
Description
On older, supported versions of Symfony (4.4, 5.3, and 5.4) the Psr16Cache
class is not compatible with psr/simple-cache:3.0.0
. Trying to use those versions together results in this error:
PHP Fatal error: Declaration of Symfony\Component\Cache\Psr16Cache::get($key, $default = null) must be compatible with Psr\SimpleCache\CacheInterface::get(string $key, mixed $default = null): mixed
Users must either upgrade to Symfony 6.0 or downgrade psr/simple-cache
to 1.x or 2.x.
Composer does not currently prevent users from installing these conflicting versions. This causes application errors for users who aren't fixing transitive dependencies like psr/simple-cache
to a specific version and use tools like composer update
or Dependabot to upgrade those transitive dependencies.
How to reproduce
Create a composer.json
file like this:
{
"require": {
"psr/simple-cache": "^3.0",
"symfony/cache": "5.4.*"
}
}
And then try running this simple PHP script:
<?php
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Psr16Cache;
require_once 'vendor/autoload.php';
$cache = new Psr16Cache(new ArrayAdapter());
The issue also occurs with symfony/cache
constraints of 5.3.*
and 4.4.*
.
Possible Solution
I see two possible solutions:
- Add
psr/simple-cache
as a non-dev dependency containing the supported version ranges; or - Add
psr/simple-cache
to theconflict
section for versions >=3.0.0
Either approach would ensure that users aren't able to install incompatible versions.
Additional Context
No response