Currently, BCMath functions only accept values as strings. If want to calculate an int type with BCMath, need to convert it to a string once, which incurs unnecessary conversion costs.
This RFC proposes adding an int type to the BCMath function argument and making the argument a union type of int and string.
That is, the function signature changes to:
function bcadd(int|string $num1, int|string $num2, ?int $scale = null): string {} function bcsub(int|string $num1, int|string $num2, ?int $scale = null): string {} function bcmul(int|string $num1, int|string $num2, ?int $scale = null): string {} function bcdiv(int|string $num1, int|string $num2, ?int $scale = null): string {} function bcmod(int|string $num1, int|string $num2, ?int $scale = null): string {} function bcpowmod(int|string $num, int|string $exponent, int|string $modulus, ?int $scale = null): string {} function bcpow(int|string $num, int|string $exponent, ?int $scale = null): string {} function bcsqrt(int|string $num, ?int $scale = null): string {} function bccomp(int|string $num1, int|string $num2, ?int $scale = null): int {} function bcround(int|string $num, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): string {}
Note that even if the only numbers passed as arguments are ints, the return value will always be a string.
I do not change anything for the following three functions. bcscale()
is not a calculation function, so exclude it. bcfloor()
and bcceil()
are excluded because there is no point in allowing int type arguments due to the characteristics of their functions.
function bcscale(?int $scale = null): int {} function bcfloor(string $num): string {} function bcceil(string $num): string {}
Any code that uses strict types and expects an error to occur when passing an int to these functions is affected because the error no longer occurs.
next PHP 8.x (8.4)
None.
Only BCMath.
None.
None.
None.
None.
There is no effect on anything other than BCMath.
None.
There is a yes/no choice whether to accept this RFC and requires a 2/3 majority vote to be accepted.
yet
yet
None.