Menu

Error Identifier: logicalOr.rightAlwaysFalse

← Back to logicalOr.*

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(bool $flag): bool
{
	$f = false;
	return $flag or $f;
}

Why is it reported? #

The right side of the or operator always evaluates to false. This typically happens because the right-side expression is a value that is always falsy, because the left side already covers all the cases where the right side could be true, or because the type of the expression on the right side is narrowed to a point where it can never be true. The right operand is redundant and likely indicates a logic error.

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

In the example above, $f is always false, so the right side of or never contributes to the result.

How to fix it #

Remove the redundant right side:

 <?php declare(strict_types = 1);
 
 function doFoo(bool $flag): bool
 {
-	$f = false;
-	return $flag or $f;
+	return $flag;
 }

Or fix the right side to test a meaningful condition:

 <?php declare(strict_types = 1);
 
-function doFoo(bool $flag): bool
+function doFoo(bool $flag, bool $other): bool
 {
-	$f = false;
-	return $flag or $f;
+	return $flag or $other;
 }

How to ignore this error #

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

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

Rules that report this error #

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