-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
number_format function gives an out of memory error for bad $decimals value #17384
Comments
Some limit is reasonable, given that floating point numbers don't have infinite precision anyway. I'm not in favor of returning an incorrect result though (i.e. |
Hmm, according to https://3v4l.org/TTcKA, this always errored (for some reasonable memory_limit). Anyhow, I think we had a similar issue regarding the INI setting |
I think memory exhaustion is correct in this case. In the case of e.g. If limit the maximum value of Specifying a value large enough to cause memory exhaustion is a rare case, so I think there is no problem with leaving it as it is :) edit: In practice, specifying a precision small than the given floating point number will result in an error being displayed and meaningless numbers being created, but I don't see any strong reason to prohibit this at present. |
I think checking an argument for a valid range is a good idea. There is no reason to have a preventable error that causes a system failure. I would recommend the parameter be validated and changed to a reasonable value between 0 and say 20. Something like |
Yeah, I don't really see the point in having a memory exhaustion when a simple range check and throw a ValueError is an option we have. The range should be in sync for the |
The float range is 2.2250738585072014e-308 - 1.7976931348623158e+308 so 2nd parameter should be limited to about int<-350, 350>. |
Off the top of my head, |
I don't have a strong opinion, so I'm not against using a valid range. However, since |
Description
The following code:
Resulted in this output:
But I expected this output instead:
This is obviously not a high priority issue, as the $decimal parameter is invalid, but thought I would report it.
It produces the output of "1" in PHP versions 8.0.30 and 7.4.33. I would consider this an acceptable value. Or maybe 1.23456, or an error message, thrown exception, but not memory exhaustion.
This is easily solved by validation the $decimal parameter, so not high priority.
PHP Version
8.4.0, 8.3.14, 8.2.26, 8.1.31
Operating System
Windows
The text was updated successfully, but these errors were encountered: