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

if (with assignment to existing variable and type checking) is always false #2499

Closed
yura3d opened this issue Oct 10, 2019 · 5 comments
Closed
Labels
Milestone

Comments

@yura3d
Copy link

yura3d commented Oct 10, 2019

Bug report

If I declare a variable and set a value of some type to it (let it be int, like in code snippet), change its value (mixed in snippet) in if statement and check the variable to be another type (string in snippet) in the same if statement, I get "If condition is always false".

Code snippet that reproduces the problem

https://phpstan.org/r/884e2c78-c95c-46f8-8a01-0d990cddee0a

Expected output

No errors, like it works when the variable is not declared before if statement

@yura3d yura3d changed the title if (with assignment to existing variable and type checking) always false if (with assignment to existing variable and type checking) is always false Oct 10, 2019
@ondrejmirtes
Copy link
Member

Hi, you got operators priority wrong. PHPStan is right.

Compare: https://3v4l.org/tL3B1 with https://3v4l.org/eXP58.

@ondrejmirtes
Copy link
Member

Sorry, looks like it should not be reported: https://3v4l.org/DbMmp

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 30, 2019
@phpstan-bot
Copy link
Contributor

@yura3d After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-5: If condition is always false.
+5: If condition is always false.
+5: Result of && is always false.
Full report
Line Error
5 If condition is always false.
5 Result of && is always false.

@phpstan-bot
Copy link
Contributor

@yura3d After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-5: If condition is always false.
+No errors

@github-actions
Copy link

github-actions bot commented Aug 1, 2023

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 Aug 1, 2023
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

3 participants