Menu

← Back to logicalOr.*

Error Identifier: logicalOr.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 $x): void
{
	if (($x > 10) or ($x < 0) or ($x === 5)) {
		return;
	}

	// At this point $x is >= 0 and <= 10 and not 5
	$result = ($x > 10) or ($x < 0); // ERROR: Result of or is always false.
}

Why is it reported? #

PHPStan determined that the result of the or expression is always false. Both the left side and the right side are always false, making the entire expression always false. This usually indicates dead code, a logic error, or a condition that has already been checked earlier in the control flow.

The or keyword is the low-precedence version of ||. This identifier specifically covers the or keyword; for ||, see booleanOr.alwaysFalse.

How to fix it #

Review the logic and remove the redundant condition or fix the expression to test what was actually intended:

 <?php declare(strict_types = 1);
 
 function doFoo(int $x): void
 {
 	if (($x > 10) or ($x < 0) or ($x === 5)) {
 		return;
 	}

-	$result = ($x > 10) or ($x < 0);
+	$result = ($x >= 5) or ($x <= 2);
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\BooleanOrConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.