Skip to content

Disallow passing array as number to NumberFormatter::format() #5181

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 4 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Feb 15, 2020

Array to number conversion makes no sense here, and is likely to hide
a programming error. Therefore we disallow passing an array in the
first place.


This is a follow-up to #5141 (comment). Given PR #5092 is work in progress, I've not spend much time on constructing a good error message.

Array to number conversion makes no sense here, and is likely to hide
a programming error.  Therefore we disallow passing an array in the
first place.
@cmb69 cmb69 force-pushed the cmb/numfmt_format-no-array branch from 7a939df to bf14447 Compare February 15, 2020 09:55
@Girgias
Copy link
Member

Girgias commented Feb 15, 2020

Wouldn't it maybe be better to say that the value must be a scalar? Slight glimpse at the source code but non-stringable object should probably also throw.

(and small drive-by but the invalid format should also throw a ValueError but that should probably be done while converting most of them from the extension)

@nikic
Copy link
Member

nikic commented Feb 15, 2020

Eh, maybe accept int|float directly? We only have that in fast zpp right now though.

@Girgias
Copy link
Member

Girgias commented Feb 15, 2020

Eh, maybe accept int|float directly? We only have that in fast zpp right now though.

I'm imagining some people might use strings directly but that does seem like a more reasonable choice indeed.

@nikic
Copy link
Member

nikic commented Feb 15, 2020

@Girgias That's fine as long as they use weak types. For strict types a string should of course throw.

@Girgias
Copy link
Member

Girgias commented Feb 15, 2020

@Girgias That's fine as long as they use weak types. For strict types a string should of course throw.

Indeed, makes sense :)

This port of `Z_PARAM_NUMBER` is particularly useful for
`zend_parse_method_parameters()`.
We also remove two test cases, since these have been degenerated to ZPP
tests.
@cmb69
Copy link
Member Author

cmb69 commented Feb 16, 2020

Eh, maybe accept int|float directly?

Yes, makes perfect sense.

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG. As this is the only use of n in (normal) zpp right now, I'd suggest adding an explicit test for the case where it throws.

@cmb69
Copy link
Member Author

cmb69 commented Feb 16, 2020

Thanks! I've re-added the adapted bug48227.phpt, and applied as 6ee6097.

@cmb69 cmb69 closed this Feb 16, 2020
@cmb69 cmb69 deleted the cmb/numfmt_format-no-array branch February 16, 2020 15:50
@carusogabriel carusogabriel added this to the PHP 8.0 milestone May 29, 2020
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.

4 participants