-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Open
Description
Symfony version(s) affected
7.3.2
Description
When upgrading from 7.2 to 7.3, it was noticed that the ServiceLocator began to operate with numeric identifiers instead of string ones. At the same time, generics indicate that $id must be a string, so when casting to string we see useless cast from static analyzers.
How to reproduce
DI:
$container->registerForAutoconfiguration(SomeInterface::class)
->addTag('some_tag');
$container->setDefinition(
id: SomeRegistry::class,
definition: new Definition(
class: SomeRegistry::class,
arguments: [
'$services' => new ServiceLocatorArgument(new TaggedIteratorArgument('some_tag')),
],
),
);
Registry:
// SomeInterface extends \Stringable
/** @var array<string, string> */
private array $serviceMap;
/**
* @param ServiceCollectionInterface<SomeInterface> $services
*/
public function __construct(private ServiceCollectionInterface $services)
{
foreach ($this->services->getIterator() as $id => $service) {
$this->serviceMap[(string) $service] = $id;
}
}
$serviceMap contains
7.2:
A => Service\A
B => Service\B
7.3:
A => 0
B => 1
Possible Solution
Problem may be here:
https://github.com/symfony/symfony/pull/60691/files#diff-2a36924e0448b459f1261198e19953b5a8f143a591a7298c18f0bb47ba04b6bbR91
https://github.com/symfony/symfony/pull/60691/files#diff-2a36924e0448b459f1261198e19953b5a8f143a591a7298c18f0bb47ba04b6bbR115
https://github.com/symfony/symfony/pull/60691/files#diff-2a36924e0448b459f1261198e19953b5a8f143a591a7298c18f0bb47ba04b6bbL113
Additional Context
No response