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
Result of && is always false. #2870
Comments
Hi, PHPStan correctly knows that If you have a more precise code sample with your problem, please post it. |
Oh, I get it, in the first iteration, the array is empty. So PHPStan should not complain. Thanks. |
Hi, I'm getting the same error for this code: https://phpstan.org/r/f90376e0-9612-4994-b515-0725a248e756 |
@davidkudera In your case PHPStan is right. At no point is |
@ondrejmirtes Yeah, but at the first iteration |
@davidkudera PHPStan reports Left side of && is always true. It wants to say you that using $a variable in your loop is useless. |
You can simplify the code without changing how it behaves: https://phpstan.org/r/aea94433-f31e-4d97-a668-25689ecb69d5 |
Oh, sorry, I should probably ask for new glasses... My problem is with "right" side of I tried to simplify my actual code a bit less for the playground, but I'm unable to reproduce my error (Right side of && is always false) there. Also, the same file (copy-paste) shows no error in another project. |
Isn't it about the |
You're right. I have that error only when I set it to I'll remove that option from my config. Thank you |
You should really reproduce it in the playground, I need it for a regression test case. I know about this problem, but I need more data. |
Here you go: https://phpstan.org/r/bb5d6c90-4df9-4174-b16d-caee1296f944 I had to start from my minimal example and add more and more code. The last line I added was the culprit (the method call on line 23). The workaround is also interesting - just flip lines 22 and 23 and it will work without any errors. |
Perfect! This helps me tremendously! |
Fixed, thank you! phpstan/phpstan-src@a086c3c |
@ondrejmirtes you closed the issue, but the initial problem is still not solved. |
Sorry, @davidkudera’s issue is resolved, the one in OP is unrelated. |
Is this related: https://phpstan.org/r/73c7b029-ffbf-4b15-b6fe-19a5f6ee43d5 ? |
@eigan Definitely not. |
Enabling "Strict rules" brings back this bug https://phpstan.org/r/e52e08c5-e090-4a07-b323-7ea9521fa07f |
An error above could be fixed with annotation /** @var string[] $arr */
$arr=[]; But I believe it's wrong. |
@ondrejmirtes PHPStan now reports different result with your code snippet: @@ @@
-6: Result of && is always false.
-6: Call to function in_array() with arguments 'test', array<int, 'test'> and true will always evaluate to true.
+6: Call to function in_array() with arguments 'test', array<int, 'test'> and true will always evaluate to true.
+6: Result of && is always false. Full report
|
@davidkudera PHPStan now reports different result with your code snippet: @@ @@
-18: Right side of && is always false.
+No errors |
@davidkudera After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+13: While loop condition is always true. Full report
|
@davidkudera After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-18: Right side of && is always false.
+17: While loop condition is always true. Full report
|
@davidkudera After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-18: Right side of && is always false.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md Full report
|
@SergeC After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-11: Call to function in_array() with arguments 'a'|'b'|'c', array<int, 'a'|'b'|'c'> and true will always evaluate to true.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-6: Result of && is always false.
-6: Call to function in_array() with arguments 'test', array<int, 'test'> and true will always evaluate to true.
+6: Call to function in_array() with arguments 'test', array<int<0, max>, 'test'> and true will always evaluate to true.
+6: Result of && is always false. Full report
|
@SergeC After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-11: Call to function in_array() with arguments 'a'|'b'|'c', array<int, 'a'|'b'|'c'> and true will always evaluate to true.
+11: Call to function in_array() with arguments 'a'|'b'|'c', array<int<0, max>, 'a'|'b'|'c'> and true will always evaluate to true. Full report
|
@aivchen 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 After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-6: Result of && is always false.
-6: Call to function in_array() with arguments 'test', array<int, 'test'> and true will always evaluate to true.
+No errors |
@SergeC After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-11: Call to function in_array() with arguments 'a'|'b'|'c', array<int, 'a'|'b'|'c'> and true will always evaluate to true.
+No errors |
Fixed: phpstan/phpstan-src@4321374 |
Closes phpstan/phpstan#5759 Closes phpstan/phpstan#5668 Closes phpstan/phpstan#5496 Closes phpstan/phpstan#4666 Closes phpstan/phpstan#3892 Closes phpstan/phpstan#3314 Closes phpstan/phpstan#2870 Closes phpstan/phpstan#5354
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 shouldn't report any errors in this case because it can't predict what rand() returns.
Code snippet that reproduces the problem
https://phpstan.org/r/e7652aad-b990-4aa7-8b6e-eeed31adc036
Expected output
No errors.
The text was updated successfully, but these errors were encountered: