Re: [RFC] On the need of a `is_int_string` ?
| From: | Rob Landers | Date: | Fri, 23 Aug 2024 21:21:36 +0000 |
| Subject: | Re: [RFC] On the need of a `is_int_string` ? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-125172@lists.php.net to get a copy of this message | ||
On Fri, Aug 23, 2024, at 23:10, Vincent Langlet wrote:
> I found a simpler implementation later which rely on array_keys
> ```
> fn is_int_string(string $s): bool => \is_int(array_keys([$s => null])[0]);
> ```
>
> I considered that
is_int_string was better in the same
> namespace than
> is_object, is_array, U
> 'ô"pu÷uöämÞis_int, is_numeric, ... but maybe
> there was something better
> than int_string to describe this category of string since
> english is not good (integish ? integable ? integerable ?).
> But indeed it could be interesting to relate this method to the array namespace...
Don't forget to bottom post!
I'm curious which one is faster/more efficient. :)
> Anyway, this topic does not seems to interest lot of developer so far ^^'
I think it would be worth writing an RFC for. While super-niche feeling, I was literally bit by this
the other day when storing what I thought were numbers as keys, but it turned out they got stored as
strings (2-digit numbers, and the zero-prefix bit me). That being said, I'm not sure how this
function would have helped me (other than tossing in a few asserts to make sure things were sane).
So, writing an RFC will force you to think about usecases like that and some examples to highlight
the issue it helps solve.
— Rob