Menu
Error Identifier: greaterOrEqual.alwaysFalse
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): void
{
if ($value >= 0) {
return;
}
if ($value >= 0) {
echo 'non-negative';
}
}
Why is it reported? #
The >= comparison is always false based on the types of the compared values. PHPStan determined from the control flow that the condition can never be true. This indicates dead code or a logic error.
How to fix it #
Review the logic and remove the always-false condition, or fix the comparison:
<?php declare(strict_types = 1);
function check(int $value): void
{
if ($value >= 0) {
return;
}
- if ($value >= 0) {
- echo 'non-negative';
- }
+ echo 'negative: ' . $value;
}
How to ignore this error #
You can use the identifier greaterOrEqual.alwaysFalse to ignore this error using a comment:
// @phpstan-ignore greaterOrEqual.alwaysFalse
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: greaterOrEqual.alwaysFalse
Rules that report this error #
- PHPStan\Rules\Comparison\NumberComparisonOperatorsConstantConditionRule [1]