-
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
is_finite, is_infinite, is_nan wrong input type argument #17809
Comments
No, floats have a much larger range than integers (though they begin losing accuracy at a certain point).
"Kicks in"?
Every integer is always finite, never infinite, and never NaN. Because "infinite" and "NaN" correspond to very specific IEEE definitions that only apply to floating-point numbers. Saying it's not possible "yet" implies that it could ever be, but there's really no reason to believe that will ever happen.
Those functions have completely different use cases:
If strict_types is not active then this is already supported naturally by PHP's loose typing system.
You're free to bring up allowing commas in string->number conversions on the PHP internals list, but I can all but guarantee there will not be much support for it. In fact PHP has gone through some effort to make sure that doesn't happen. If you want a way to convert a locale-formatted numeric string to a number then I suggest checking if the intl extension has something that can do it.
As mentioned, PHP fully supports string values as parameters to those functions, but not when using strict_types. So if you're getting a "argument must be of type float, string given" error then that means your templating engine is using strict_types (which also means you may have similar problems with many other functions). Or perhaps it implements its own custom support for that functionality instead of directly using the is_* functions. All in all, everything here appears to be behaving as expected: the three functions support floats and integers (even though all integers are always finite), they support numeric strings (if strict_types is not enabled), and they do not support the other data types (because apples are not oranges). |
Please don't do that. English is not everybody's first language, and mocking them for it is not productive or welcoming. But as Damian mentioned, nan, inf and -inf are all IEEE-754 concepts. They are not a thing for integers. If you want a more lax function that accepts ints and always returns false for them, creating a wrapper function would be trivial. |
i believe that an integer between PHP_INT_MIN and PHP_INT_MAX constants are considered finite, anything else would be infinite / out of range also for nan, between the constants PHP_INT_MIN and PHP_INT_MAX a integer is considered a number, outside these a nan ? |
@remco-pc There are no values below |
Description
The following functions
have the argument as a float.
I believe float ranges are smaller then integer ranges (so is_finite kicks in earlier on a float then on an integer (where the last one is not possible yet))
Also i believe these functions should accept mixed (like is_int & is_float use) and should convert a numeric string to an integer or a float (wheter it has a comma or not).
this all for the easier way of writing it in templating string like
PHP Version
php8.3.15
Operating System
Debian 12
The text was updated successfully, but these errors were encountered: