website/errors/preInc.nonNumeric.md
This error is reported by phpstan/phpstan-strict-rules.
<?php declare(strict_types = 1);
function increment(bool $flag): int
{
return ++$flag;
}
The ++ (pre-increment) operator is being used on a value that is not numeric. While PHP allows incrementing non-numeric types like bool, this behaviour can be surprising and error-prone. The strict rules require that only numeric types (int or float) are used with the increment operator to prevent unintended results.
Ensure the variable is typed as int if you intend numeric increment:
<?php declare(strict_types = 1);
-function increment(bool $flag): int
+function increment(int $counter): int
{
- return ++$flag;
+ return ++$counter;
}