Skip to content

Allow number_format to be only passed 3 arguments #5977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Aug 12, 2020

Should I also drop the PHPAPI _php_math_number_format() function?

@Girgias Girgias force-pushed the number_format-optional-args branch from ec90ecc to 71d512a Compare August 12, 2020 22:47
@thg2k
Copy link
Contributor

thg2k commented Aug 12, 2020

I don't think taking null as default is appropriate here, 3 and 4 are string, not ?string, and it would not be consistent with the other builtins. Default keyword, anyone?

@Girgias
Copy link
Member Author

Girgias commented Aug 12, 2020

I don't think taking null as default is appropriate here, 3 and 4 are string, not ?string, and it would not be consistent with the other builtins. Default keyword, anyone?

PHP 7.4 already accepts null as can be seen here: https://heap.space/xref/PHP-7.4/ext/standard/math.c?r=d90cdbd9#1261

This is even easier to see by looking at it's signature from the stubs, the source of truth, which is function number_format(float $number, int $decimals = 0, ?string $decimal_point = "." , ?string $thousands_separator = ","): string {}

Anyway the default keyword thing is completely useless since we got named arguments in PHP 8.0 and moreover null is the correct semantics to get the default behaviour.

About the "inconsistency" in regards to other built-in functions. We are making the arguments of other built-in functions nullable because what happens in effect is function overloading which is only possible for internal functions and we want to align internal and userland behaviour.

Therefore could you please do some research into the various changes made in the engine for this major version before coming up with a supposedly solution which has already been declined in the past, see https://wiki.php.net/rfc/skipparams

@nikic
Copy link
Member

nikic commented Aug 13, 2020

@Girgias We do try to avoid nullability if there is a possibility to write the default value explicitly -- which there is in this case. Unfortunately the nullability support is preexisting, so dropping it is a BC break. Maybe the fact that null support is not documented gives us the necessary leeway to do that?

@nikic
Copy link
Member

nikic commented Aug 13, 2020

On the other hand, it looks like null support in this function is really old: 6d7cac7 I don't thin it's worth breaking functionality that has existed since 2004 and doesn't really cost us to maintain.

@php-pulls php-pulls closed this in 9cb5221 Aug 13, 2020
@Girgias Girgias deleted the number_format-optional-args branch September 15, 2020 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants