Menu

← Back to logicalAnd.*

Error Identifier: logicalAnd.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 and $i > 0;
	if ($result) {
		// ...
	}
}

Why is it reported? #

The result of the and expression is always true. Both sides of the logical AND are always true given the types and conditions involved, making the check redundant. This often indicates duplicated conditions or overly broad type constraints that make the test meaningless.

How to fix it #

Remove the redundant condition:

 function doFoo(int $i): void
 {
-	$result = $i > 0 and $i > 0;
+	$result = $i > 0;
 	if ($result) {
 		// ...
 	}
 }

Or replace the duplicated condition with the intended check:

 function doFoo(int $i): void
 {
-	$result = $i > 0 and $i > 0;
+	$result = $i > 0 and $i < 100;
 	if ($result) {
 		// ...
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\BooleanAndConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.