alphp / strftime

This provides a cross-platform alternative to strftime() for when it will be removed from PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replace "is_int" check with "is_numeric"?

garvinhicking opened this issue · comments

Hi!

I believe that this code:

 $timestamp = is_int($timestamp) ? '@' . $timestamp : (string) $timestamp;

should better be:

$timestamp = is_numeric($timestamp) ? '@' . $timestamp : (string) $timestamp;

because there might be places where a "string" like "168023423" is passed (typed as a string), but DateTime constructor will then complain if it's passed as a string. is_numeric() would be the better choice to see if a variable only contains numbers...?

Regards,
Garvin

commented

Not a good idea. Because then '1337e0' for example will be treated as a timestamp, and it's not. If you have a string, you should force-type it: (int)$timestamp.

Generally I'd agree and many thanks for getting onto it.

But this library is used for drop-in replacement where refactoring is cumbersome. So IMO the lib should accept the input that older PHP accepted before...?

Maybe use a combination of is_string() && ctype_digit() (however that has this odd "small integer" issue), or use is_string() && is_numeric()?

IMO it fixes more issues with a "string" timestamp than new issues would be raised with "1337e0"-like cases, that would probably not have been in there in old strftime() calls?