Open
Description
Symfony version(s) affected
5.4 up to 7.x
Description
ParameterBag
is documented to have string
keys. This is incorrect, in practice the key type is string|int
.
This is due to the fact that the PHP runtime will cast any numeric-string
used as an array key to a real integer
.
How to reproduce
Parse a request with numeric parameter names in the query string (ie: https://domain.tld/search?0=value&78=something
). The query parameter bag will have integers in its keys.
Possible Solution
The typehint should be \IteratorAggregate<string|int, mixed>
(same thing for the getIterator()
method).
Or the component should enforce the key type in the method keys()
and getIterator()
, but this is potentially a breaking change.
Additional Context
This is related to: phpstan/phpstan-symfony#439