简体   繁体   中英

strtotime and checking if valid timestamp

I am experiencing an issue with strtotime.

$data['task_time_due'] = strtotime("+1 day");

This returns false..

$this->Utility->is_timestamp_valid($data['task_time_due'])

Utility.php..

function is_timestamp_valid($timestamp)
{
    return ((string) (int) $timestamp === $timestamp) 
    && ($timestamp <= PHP_INT_MAX)
    && ($timestamp >= ~PHP_INT_MAX);
}

Anyone know why? This function works great throughout my application.

'Cause strtotime returns int and you are comparing it strictly with string. Change this (string) (int) $timestamp === $timestamp to this (int)(string) $timestamp === $timestamp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM