Menu
Error Identifier: spaceship.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 compare(int $number, object $item): int
{
return $number <=> $item;
}
Why is it reported? #
The spaceship operator (<=>) is used to compare two values, but the types of the operands are not compatible for comparison. PHP cannot meaningfully compare a numeric type against an object or array using this operator, and it results in an error.
How to fix it #
Make sure both sides of the spaceship operator are of compatible types.
<?php declare(strict_types = 1);
-function compare(int $number, object $item): int
+function compare(int $number, int $other): int
{
- return $number <=> $item;
+ return $number <=> $other;
}
How to ignore this error #
You can use the identifier spaceship.invalid to ignore this error using a comment:
// @phpstan-ignore spaceship.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: spaceship.invalid
Rules that report this error #
- PHPStan\Rules\Operators\InvalidComparisonOperationRule [1]