Error Identifier: notIdentical.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(): void
{
$value = 1;
if ($value !== 1) {
// never entered
}
}
Why is it reported? #
The strict comparison using !== always evaluates to false because both sides are known to have the same value at that point in the code. In the example above, $value is always 1, so $value !== 1 is always false. This makes the condition unreachable.
How to fix it #
Remove the unreachable condition:
<?php declare(strict_types = 1);
function doFoo(): void
{
$value = 1;
- if ($value !== 1) {
- // never entered
- }
}
Or fix the logic to compare the correct variable.
How to ignore this error #
You can use the identifier notIdentical.alwaysFalse to ignore this error using a comment:
// @phpstan-ignore notIdentical.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: notIdentical.alwaysFalse
Rules that report this error #
- PHPStan\Rules\Comparison\StrictComparisonOfDifferentTypesRule [1]