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

Incorrect "variable might not be defined" when using "continue 2" #1283

Closed
stof opened this issue Jul 24, 2018 · 13 comments
Closed

Incorrect "variable might not be defined" when using "continue 2" #1283

stof opened this issue Jul 24, 2018 · 13 comments

Comments

@stof
Copy link
Contributor

stof commented Jul 24, 2018

Summary of a problem or a feature request

When the code is using continue 2 for a switch inside a loop, the variable defined in all other cases of the switch is still marked as not defined for the code running in the loop after the switch block, while it cannot be the case.

Code snippet that reproduces the problem

https://phpstan.org/r/7ea8280d7f815b255e3f5528dc5c4262

Expected output

should not detect any issue

@ondrejmirtes
Copy link
Member

continue 2 is not yet supported but it's gonna be when the NodeScopeResolver refactoring is complete.

@stof
Copy link
Contributor Author

stof commented Jul 25, 2018

is it a refactoring which is in progress, or only something planned for the future with no idea about when it will happen ?

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Jul 25, 2018 via email

@ondrejmirtes ondrejmirtes added this to the NodeScopeResolver bugs milestone Jan 12, 2019
@stof
Copy link
Contributor Author

stof commented Apr 3, 2019

@ondrejmirtes what is the status of this bug, now that the refactoring has landed in 0.11.3 ?

@b1rdex
Copy link
Contributor

b1rdex commented May 27, 2019

We are facing same bug with continue 2 in switch inside for loop. Had to predefine variables before switch.

@stof
Copy link
Contributor Author

stof commented Nov 5, 2019

@ondrejmirtes any news on that one ?

@ondrejmirtes
Copy link
Member

@stof If there was any news, this issue would be closed. It's low priority for me. You can always persuade PHPStan with an additional isset.

@Yivan
Copy link

Yivan commented Feb 14, 2020

Hello,

We are getting the same problem it seems, here an example in a more really simple case:
https://phpstan.org/r/1d022bea-77f7-47a1-946b-9e2417712de0

Is it or should separate issue bien open ?

This is somehow problematic because this leads to making specific code because phpstan cannot see iner declaration in same if condition.
I understand this could be hard to achieve.

@ondrejmirtes what is your recommendation on this please ? Better left the code like this and ignoring the error in config file waiting phpstan handle this, or refactor the code ?

Thanks a lot.

@Yivan
Copy link

Yivan commented Feb 14, 2020

I should add, this is strange because here in the complete exemple:
https://phpstan.org/r/c56f33a7-ef29-432b-8465-e8c8b9fddc00

It doesn't complain on line 69 strangely, but complain on line 87 !?

@stof
Copy link
Contributor Author

stof commented Feb 14, 2020

@Yivan writing in an array does not require the variable to exist in PHP. It will happily create it.

@Yivan
Copy link

Yivan commented Feb 14, 2020

@stof You are totally right ! My bads. So seems my problem is on the right issue, same than the original post about declaration in if condition.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@31fcad6

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants