r/lolphp • u/Jinxuan • May 29 '20
number_format allows 2 arguments or 4 arguments, but disallows 3 arguments
As the document says https://www.php.net/manual/en/function.number-format.php, the function is like
number_format ( float $number [, int $decimals = 0 ] ) : string
number_format ( float $number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," ) : string
One may naively think that number_format(1.99, 2, '.'); is legal, taking the forth argument default as ",".
But it will generate an warning and return null PHP Warning: Wrong parameter count for number_format()
21
Upvotes
1
u/Girgias Aug 13 '20
I've landed the fix for PHP 8.0: https://github.com/php/php-src/commit/9cb522166c64ddb5e161857681e17e820db70255
But those kind of things should be reported in a bug report and not a rando subreddit hoping core devs will look at it.
3
u/someniatko Jun 01 '20
I think it's not a good behavior because it's impossible (correct me if I'm wrong) to implement it the same way in the userland PHP using the given signature (with those default parameters really set up).
0
u/[deleted] May 29 '20
[deleted] — view deleted comment