website/errors/minus.leftNonNumeric.md
<?php declare(strict_types = 1);
function subtract(bool $flag, int $b): int
{
return $flag - $b;
}
The left operand of the subtraction operator (-) is not a numeric type. PHP will attempt to coerce non-numeric values to numbers at runtime, which can lead to unexpected results or TypeError exceptions in strict mode. Only int and float types should be used in arithmetic operations.
This rule is provided by the phpstan-strict-rules package.
Ensure the left operand is a numeric type before performing subtraction:
-function subtract(bool $flag, int $b): int
+function subtract(int $a, int $b): int
{
- return $flag - $b;
+ return $a - $b;
}
Or cast the value explicitly:
function subtract(bool $flag, int $b): int
{
- return $flag - $b;
+ return (int) $flag - $b;
}