Menu

← Back to greaterOrEqual.*

Error Identifier: greaterOrEqual.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
{
	if ($i >= 2 && $i < 5) {
		if ($i >= 1) {
			// ...
		}
	}
}

Why is it reported? #

The >= comparison always evaluates to true based on the types of the operands. In the example, $i is already known to be at least 2 from the outer condition, so $i >= 1 is always true. This usually indicates a logic error, redundant condition, or incorrect comparison value.

How to fix it #

Fix the comparison to reflect the intended logic:

 function doFoo(int $i): void
 {
 	if ($i >= 2 && $i < 5) {
-		if ($i >= 1) {
+		if ($i >= 3) {
 			// ...
 		}
 	}
 }

Or remove the redundant condition:

 function doFoo(int $i): void
 {
 	if ($i >= 2 && $i < 5) {
-		if ($i >= 1) {
-			// ...
-		}
+		// ...
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\NumberComparisonOperatorsConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.