website/errors/mul.leftNonNumeric.md
<?php declare(strict_types = 1);
function multiply(bool $flag, int $b): int
{
return $flag * $b;
}
The left operand of the multiplication 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 multiplication:
-function multiply(bool $flag, int $b): int
+function multiply(int $a, int $b): int
{
- return $flag * $b;
+ return $a * $b;
}
Or cast the value explicitly:
function multiply(bool $flag, int $b): int
{
- return $flag * $b;
+ return (int) $flag * $b;
}