Menu

← Back to logicalAnd.*

Error Identifier: logicalAnd.rightAlwaysFalse

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
{
	$zero = 0;
	if ($i and $zero) { // ERROR: Right side of and is always false.
		echo 'entered';
	}
}

Why is it reported? #

The right side of the and operator always evaluates to false. In this example, $zero is always 0, which is falsy in PHP, so the right operand of the and expression is always false. This means the entire and expression is always false, and the code inside the if block will never execute. This usually indicates a logic error or a redundant check.

How to fix it #

Remove the redundant right side or fix the variable:

 <?php declare(strict_types = 1);
 
 function doFoo(int $i): void
 {
-	$zero = 0;
-	if ($i and $zero) {
+	if ($i) {
 		echo 'entered';
 	}
 }

Or fix the logic to check the correct variable:

 <?php declare(strict_types = 1);
 
-function doFoo(int $i): void
+function doFoo(int $i, int $j): void
 {
-	$zero = 0;
-	if ($i and $zero) {
+	if ($i and $j) {
 		echo 'entered';
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\BooleanAndConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.