Menu

← Back to logicalOr.*

Error Identifier: logicalOr.alwaysTrue

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 >= 0) or ($i < 0); // ERROR: Result of or is always true.
}

Why is it reported? #

PHPStan determined that the result of the or expression is always true. At least one side of the operator is guaranteed to be truthy regardless of the input. In the example above, every integer is either greater than or equal to zero, or less than zero, so the entire expression is always true. This usually indicates a logic error, a redundant check, or dead code.

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

How to fix it #

Fix the logic to produce a meaningful condition:

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

Or simplify the expression if the result is intentionally always true:

 <?php declare(strict_types = 1);
 
 function doFoo(int $i): void
 {
-	$result = ($i >= 0) or ($i < 0);
+	$result = true;
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\BooleanOrConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.