Error Identifier: smaller.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 doFoo(int $i): void
{
if ($i > 5) {
if ($i < 3) {
// never reached
}
}
}
Why is it reported? #
The < (less than) comparison always evaluates to false because the types of the compared values make it impossible for the condition to be true. In this example, inside the if ($i > 5) branch, the variable $i is known to be of type int<6, max>. Comparing $i < 3 is always false because a value that is at least 6 can never be less than 3.
This usually indicates a logic error or a redundant check that can never be reached.
How to fix it #
Fix the comparison to use the correct value:
<?php declare(strict_types = 1);
function doFoo(int $i): void
{
if ($i > 5) {
- if ($i < 3) {
+ if ($i < 10) {
// ...
}
}
}
Or remove the unreachable condition entirely:
<?php declare(strict_types = 1);
function doFoo(int $i): void
{
if ($i > 5) {
- if ($i < 3) {
- // never reached
- }
+ // execute code directly
}
}
How to ignore this error #
You can use the identifier smaller.alwaysFalse to ignore this error using a comment:
// @phpstan-ignore smaller.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: smaller.alwaysFalse
Rules that report this error #
- PHPStan\Rules\Comparison\NumberComparisonOperatorsConstantConditionRule [1]