Skip to content
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

Open
PrinsFrank opened this issue Apr 19, 2024 · 3 comments
Open
Labels
Milestone

Comments

@PrinsFrank
Copy link

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!

@PrinsFrank 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
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Apr 19, 2024
@ondrejmirtes
Copy link
Member

As a workaround you can do https://phpstan.org/r/63e2f182-9ed9-4536-8d24-1d75821d9064 which makes far more sense for a match expression :)

@PrinsFrank
Copy link
Author

@ondrejmirtes Exactly what we did! But it made sense to still report this in case someone else does more assigning properties in match arms?

@ondrejmirtes
Copy link
Member

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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants