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

"Instanceof static" is treated erroneously as "instanceof self" #2231

Closed
kiler129 opened this issue Jun 20, 2019 · 4 comments
Closed

"Instanceof static" is treated erroneously as "instanceof self" #2231

kiler129 opened this issue Jun 20, 2019 · 4 comments
Labels

Comments

@kiler129
Copy link
Contributor

Bug report

A statement $foo instanceof static is treated like the static is always the same class as the class where statement is placed. This is obviously wrong, and the easiest example will be to imagine an abstract class which does such check.

Code snippet that reproduces the problem

Running example: https://3v4l.org/O87Qc
Analysis: https://phpstan.org/r/d6cb91f9-e428-4652-a8b0-16ee03ff6759

Currently the analysis reports Result of && is always false. for $x !== null && !($x instanceof static) where ?foo $x

Expected output

No error is expected. Psalm recently fixed the same problem: https://psalm.dev/r/4223401cd8

@muglug
Copy link
Contributor

muglug commented Jun 20, 2019

I fixed by treating this comparison identically to $x === $this

@phpstan-bot
Copy link
Contributor

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

@@ @@
-6: Result of && is always false.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@4acbc6c

@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 29, 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