Menu

Error Identifier: equal.alwaysFalse

← Back to equal.*

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);

/** @param positive-int $i */
function doFoo(int $i): void
{
	if ($i == 0) {
		// never reached
	}
}

Why is it reported? #

The loose comparison using == always evaluates to false based on the types of the operands. Even with PHP’s type juggling rules, these two values can never be considered equal. This indicates dead code or a logic error – the branch will never execute.

In the example above, $i is a positive-int (always >= 1), so it can never be loosely equal to 0.

How to fix it #

Fix the comparison to compare values that can actually be equal:

 /** @param positive-int $i */
 function doFoo(int $i): void
 {
-	if ($i == 0) {
+	if ($i == 1) {
 		// ...
 	}
 }

Or use strict comparison (===) if the intent is to compare identical types:

 /** @param positive-int $i */
 function doFoo(int $i): void
 {
-	if ($i == 0) {
+	if ($i === 1) {
 		// ...
 	}
 }

How to ignore this error #

You can use the identifier equal.alwaysFalse to ignore this error using a comment:

// @phpstan-ignore equal.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: equal.alwaysFalse

Rules that report this error #

  • PHPStan\Rules\Comparison\ConstantLooseComparisonRule [1]
Theme
A
© 2026 PHPStan s.r.o.