-
Notifications
You must be signed in to change notification settings - Fork 94
ParameterBag->keys()
return type is incorrect
#439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
ParameterBag->keys()
return type is incorrect
The ParameterBag is documented as having string keys. See also btw, this case where PHP automatically casts numeric-string keys into an integer is a case where using strict_types in PHP is actually breaking things (without strict_types, PHP would safely cast that integer back to a numeric string when using it as a string). |
could you give a 3v4l.org example of what you mean? |
Which is also incorrect. It would be more accurate to use From a static analysis perspective, runtime behavior is the only thing that should matter. I want PHPStan to help me identify defects not to obscure them by relying on idealized type annotations that doesn't reflect actual behavior. This might warrant a follow-up issue in
This nuance is irrelevant in this context. The fact that you don’t get a |
Are you then forbidding all usages of |
Yes, if I cannot ensure the keys will be strings I do not typehint them as strings. This PHP behaviour is unfortunate but we have to deal with the language quirks. Array keys that are external/unsafe inputs should always be treated as |
In the
ParameterBag
stub the return type is improperly narrowed tolist<string>
.The implementation use a simple
array_keys
call. Therefore the return type MUST belist<array-key>
.With the current type narrowing it's impossible to correctly parse a query string with numeric keys (ie:
https://domain.tld/search?0=value&78=something
). Worse, trusting PHPStan than the key is a string might lead to a runtimeTypeError
.The text was updated successfully, but these errors were encountered: