Menu

← Back to smallerOrEqual.*

Error Identifier: smallerOrEqual.invalid

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 check(stdClass $object, int $number): bool
{
    return $object <= $number;
}

Why is it reported? #

The <= comparison operator is used between types that cannot be meaningfully compared. Comparing an object with a number produces unreliable results and is almost always a bug. PHP will attempt type juggling but the outcome is not well-defined for these type combinations.

How to fix it #

Extract a comparable value from the object before comparing:

 <?php declare(strict_types = 1);
 
-function check(stdClass $object, int $number): bool
+function check(stdClass $object, int $number, int $value): bool
 {
-    return $object <= $number;
+    return $value <= $number;
 }

How to ignore this error #

You can use the identifier smallerOrEqual.invalid to ignore this error using a comment:

// @phpstan-ignore smallerOrEqual.invalid
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: smallerOrEqual.invalid

Rules that report this error #

  • PHPStan\Rules\Operators\InvalidComparisonOperationRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.