Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Http-foundation] ParameterBag typehints are incorrect #60411

Open
@nreynis

Description

@nreynis

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions