Re: [RFC] Add "is_representable_as_float()" and "is_representable_as_int()" functions
| From: | Hans Krentel | Date: | Tue, 29 Jul 2025 16:33:57 +0000 |
| Subject: | Re: [RFC] Add "is_representable_as_float()" and "is_representable_as_int()" functions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128300@lists.php.net to get a copy of this message | ||
On Tuesday 29 July 2025 18:04:06 (+02:00), Larry Garfield wrote:
On Tue, Jul 29, 2025, at 7:52 AM, Alexandre Daubois wrote:There is prior art and also I'd personally recommend to abide to mixed to not open new gaps while closing older.Hi internals, I would like to present the RFC to add the "is_representable_as_float()" and "is_representable_as_int()" functions. These functions provide developers with a way to check whether values can be losslessly converted between integer and floating-point representations. https://wiki.php.net/rfc/is-representable-as-float-int Best, Alexandre DauboisThis looks lovely. Since only int, float, and string can ever be true, does it make sense to type the function parameters asint|float|stringrather thanmixed, to automatically exclude arrays, objects, and null? (All of which would always be false.)
php --rf is_countable
Function [ <internal:standard> function is_countable ] {
- Parameters [1] {
Parameter #0 [ <required> mixed $value ]
}
- Return [ bool ]
}
(I could probably argue either way on it, but my first inclination is yes; push the initial validation upstream. You should always know if a variable is a primitive or not, at the very least.)IMHO this is not a validation but a test function. So if you think one should know, you probably should not need this function at all. Btw. is_primitive() was not a thing last time I looked. It would be great though to have the combined test of is_scalar() and is_null() in a single function call. This is perhaps something for the line-up. Just my 2 cents -- hakre