Menu

← Back to logicalAnd.*

Error Identifier: logicalAnd.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 and $i < 3) {
		// unreachable
	}
}

Why is it reported? #

The result of the and expression is always false. Given the types and conditions involved, there is no possible value that satisfies both sides of the logical AND simultaneously. The code inside the branch is dead code and likely indicates a logic error.

How to fix it #

Fix the conditions so they can both be true at the same time:

 function doFoo(int $i): void
 {
-	if ($i > 5 and $i < 3) {
+	if ($i > 3 and $i < 5) {
 		// ...
 	}
 }

Or, if the intent was an OR condition:

 function doFoo(int $i): void
 {
-	if ($i > 5 and $i < 3) {
+	if ($i > 5 or $i < 3) {
 		// ...
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\BooleanAndConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.