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
"Variable might not be defined" when always assigning variable in match arm #10909
Labels
Milestone
Comments
PrinsFrank
changed the title
"Variable might not be defined" when Always assigning variable in match arm
"Variable might not be defined" when always assigning variable in match arm
Apr 19, 2024
As a workaround you can do https://phpstan.org/r/63e2f182-9ed9-4536-8d24-1d75821d9064 which makes far more sense for a match expression :) |
@ondrejmirtes Exactly what we did! But it made sense to still report this in case someone else does more assigning properties in match arms? |
I marked this as a bug report, it's a valid bug :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
When a variable is assigned in each arm of a match statement, it will still be reported as "Variable $foo might not be defined". The code can be rewritten to be easier to read, but this still looks like a bug.
Code snippet that reproduces the problem
https://phpstan.org/r/b99db06d-4934-4b9d-8862-778f00bee23b
Expected output
Variable $foo should always be considered defined when it is assigned in each match arm.
Did PHPStan help you today? Did it make you happy in any way?
I love PHPStan, level 9 and strict rules all the way!
The text was updated successfully, but these errors were encountered: