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
Inside foreach, $value is not the same as $array[$key] #6000
Comments
@Seldaek After the latest commit in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-8: Parameter #2 $array of function implode expects array<string>, array<int|string, array<string>|string> given.
+9: Offset 'classmap' does not exist on array{psr-4?: array<string, array<string>|string>, classmap?: array<int, string>}. Full report
|
@herndlm - I am not sure this is correct - I mean it's an improvement in that $value is now correct based on the $key check - but $data[$key] should IMO also be marked as existing within a foreach creating $key https://phpstan.org/r/47a8b19c-e77b-44b4-9272-b1eedf7b046b |
Oh, that's a bit of a weird one. Adding some internal info for @ondrejmirtes mostly and also fyi I guess :)
this raises 3 questions for me
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
Even though I narrow down which $key is currently being looped over, $value still has an aggregate type of all possible keys, and does not update to become the stricter type associated with just that exact key. Anyway the snippet probably explains this better :D
It may be a feature request more than a bug I suppose.
Code snippet that reproduces the problem
https://phpstan.org/r/456203ce-8c04-406f-b7fb-556ac8d711ca
Expected output
No error
The text was updated successfully, but these errors were encountered: