Menu
Error Identifier: if.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 process(int $value): void
{
if ($value > 10) {
return;
}
if ($value > 10) {
echo 'large';
}
}
Why is it reported? #
The if condition is always false based on the types and values PHPStan has inferred at that point in the code. The body of the if statement will never execute, making it dead code. This usually points to a logic error or redundant check.
How to fix it #
Review the surrounding logic and either remove the dead branch or fix the condition:
<?php declare(strict_types = 1);
function process(int $value): void
{
if ($value > 10) {
return;
}
- if ($value > 10) {
- echo 'large';
- }
+ echo 'not large: ' . $value;
}
How to ignore this error #
You can use the identifier if.alwaysFalse to ignore this error using a comment:
// @phpstan-ignore if.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: if.alwaysFalse
Rules that report this error #
- PHPStan\Rules\Comparison\IfConstantConditionRule [1]