Error Identifier: logicalOr.rightAlwaysFalse
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
function check(int $value): bool
{
return $value > 0 or $value > 10;
}
Why is it reported? #
The right side of the or operator always evaluates to false. This typically happens because the left side already covers all the cases where the right side could be true, or because the type of the expression on the right side is narrowed to a point where it can never be true. The condition is redundant and likely indicates a logic error.
How to fix it #
Review the logic and either remove the redundant right side or correct the condition so that it can actually evaluate to true.
<?php declare(strict_types = 1);
function check(int $value): bool
{
- return $value > 0 or $value > 10;
+ return $value > 0 or $value < -10;
}
How to ignore this error #
You can use the identifier logicalOr.rightAlwaysFalse to ignore this error using a comment:
// @phpstan-ignore logicalOr.rightAlwaysFalse
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: logicalOr.rightAlwaysFalse
Rules that report this error #
- PHPStan\Rules\Comparison\BooleanOrConstantConditionRule [1]