Menu

← Back to smaller.*

Error Identifier: smaller.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 checkAge(int $age): void
{
	if ($age < PHP_INT_MAX) {
		echo 'Always reaches here';
	}
}

Why is it reported? #

The < comparison is always true based on the types of the operands. This indicates that the condition is redundant because the left side is always strictly less than the right side given their possible values. Such comparisons often signal a logic error or an overly broad type.

How to fix it #

Remove the unnecessary condition, or adjust the comparison to reflect the actual constraint you intend to enforce.

 <?php declare(strict_types = 1);
 
-function checkAge(int $age): void
+/**
+ * @param int<0, 150> $age
+ */
+function checkAge(int $age): void
 {
-	if ($age < PHP_INT_MAX) {
+	if ($age < 18) {
 		echo 'Too young';
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\NumberComparisonOperatorsConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.