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:
> > 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 Daubois
>
> This looks lovely.
>
> Since only int, float, and string can ever be true, does it make sense
to type the function parameters as `int|float|string` rather than `mixed`,
to automatically exclude arrays, objects, and null? (All of which would
always be false.)
There is prior art and also I'd personally recommend to abide to mixed to
not open new gaps while closing older.
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