Menu

Error Identifier: logicalAnd.rightAlwaysTrue

← Back to logicalAnd.*

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
{
	$t = true;
	return $flag and $t;
}

Why is it reported? #

PHPStan determined that the right side of the and expression always evaluates to true. This means the right operand does not contribute additional filtering to the condition – the result depends solely on the left side. This usually indicates redundant logic, a copy-paste mistake, or a condition that has been made unnecessary by earlier narrowing.

The and keyword is the low-precedence version of &&. This identifier specifically covers the and keyword; for &&, see booleanAnd.rightAlwaysTrue.

In the example above, $t is always true, so the right side of and is redundant and the result depends entirely on $flag.

How to fix it #

Remove the redundant right side if it is not needed:

 <?php declare(strict_types = 1);
 
 function doFoo(bool $flag): bool
 {
-	$t = true;
-	return $flag and $t;
+	return $flag;
 }

Or fix the logic if the condition should test something different:

 <?php declare(strict_types = 1);
 
-function doFoo(bool $flag): bool
+function doFoo(bool $flag, bool $other): bool
 {
-	$t = true;
-	return $flag and $t;
+	return $flag and $other;
 }

How to ignore this error #

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

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

Rules that report this error #

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