MIR0213
PossiblyInvalidOperand
An operator is applied to a value whose type is a union, and at least one member of that union is not compatible with the operator. At runtime the operation may succeed or fail depending on which branch of the union is actually present.
Example
Section titled “Example”<?phpfunction double(int|string $value): int|float { return $value * 2; // string is not a valid operand for *}How to fix
Section titled “How to fix”Narrow the type before applying the operator, or ensure all union members are compatible:
<?phpfunction double(int|string $value): int|float { if (!is_int($value)) { throw new \InvalidArgumentException('Expected int'); } return $value * 2;}