Menu

← Back to booleanAnd.*

Error Identifier: booleanAnd.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
{
	$result = $i > 5 && $i < 3;
}

Why is it reported? #

The result of the && (boolean AND) expression always evaluates to false. This happens when it is impossible for both sides of the operator to be truthy at the same time. In the example above, $i cannot be both greater than 5 and less than 3 simultaneously, so the entire expression is always false. This usually indicates a logic error or dead code.

How to fix it #

Fix the logic so that both conditions can be satisfied:

 <?php declare(strict_types = 1);
 
 function doFoo(int $i): void
 {
-	$result = $i > 5 && $i < 3;
+	$result = $i > 3 && $i < 5;
 }

Or remove the expression entirely if the code block is unreachable:

 <?php declare(strict_types = 1);
 
 function doFoo(int $i): void
 {
-	$result = $i > 5 && $i < 3;
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\BooleanAndConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.