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
False positive: constant in abstract class #2959
Comments
You can use |
@ondrejmirtes you're right, that's a lot better solution for my code! I guess I should stop using |
@tbmatuka PHPStan now reports different result with your code snippet: @@ @@
+No errors
+
+PHP 7.1 – 7.3 (1 error)
+==========
+
12: Strict comparison using === between '' and '' will always evaluate to true. Full reportPHP 7.4 – 8.0No errors PHP 7.1 – 7.3 (1 error)
|
@tbmatuka After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-12: Strict comparison using === between '' and '' will always evaluate to true.
+No errors |
Fixed: phpstan/phpstan-src@4cb02d1 |
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. |
Bug report
phpstan considers $this::CONSTANT the same as self::CONSTANT, which it shouldn't.
Code snippet that reproduces the problem
https://phpstan.org/r/f9cd163f-bcf1-4547-b332-264c94aebb5c
Expected output
$this::CONSTANT in a non-final class (and especially an abstract one) should not be considered as the value that it is set to in the current class.
Usecase
I'm using doctrine and I have an abstract repository class that I extend for all of my repositories. To avoid duplicating the constructor, I set a constant to the entity class name and use it in the constructor. This gives me a single clean line of code at the beginning of the class to make it work.
Temporary workaround
I created a function in the abstract class that returns $this::CONSTANT and used the result of that in the constructor. It's ugly, but it avoids triggering the bug.
The text was updated successfully, but these errors were encountered: