Menu

← Back to booleanAnd.*

Error Identifier: booleanAnd.rightAlwaysTrue

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
{
	$one = 1;
	if ($i && $one) {
		// ...
	}
}

Why is it reported? #

The right side of the && (boolean AND) expression always evaluates to true. When the right operand is always truthy, it has no effect on the result of the expression – the outcome depends entirely on the left operand. This indicates a redundant check, a logic error, or a variable that should hold a different value.

In the example above, $one is always 1, which is truthy in PHP, so the right side of && is always true and the condition is equivalent to just if ($i).

How to fix it #

Remove the redundant right operand:

 <?php declare(strict_types = 1);
 
 function doFoo(int $i): void
 {
-	$one = 1;
-	if ($i && $one) {
+	if ($i) {
 		// ...
 	}
 }

Or fix the logic to use a variable whose value is not always truthy:

 <?php declare(strict_types = 1);
 
-function doFoo(int $i): void
+function doFoo(int $i, bool $flag): void
 {
-	$one = 1;
-	if ($i && $one) {
+	if ($i && $flag) {
 		// ...
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\BooleanAndConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.