[php-src] Issue #12724: strtotime() doesnt return false when a timestamp input given.
| From: | MMMahmoodian | Date: | Sun, 19 Nov 2023 12:22:29 +0000 |
| Subject: | [php-src] Issue #12724: strtotime() doesnt return false when a timestamp input given. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245841@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12724
Author: MMMahmoodian
### Description
The following code:
```php
<?php
var_dump(strtotime(1700394677));
```
Resulted in this output:
```
int(85452598839)
```
But I expected this output instead:
```
bool(false)
```
Extra context:
We have a code that checks whether an input is either a UNIX timestamp or datetime. We were using
strtotime() to check if the input is datetime or not. This morning we faced many errors
due to this bug. strtotime should return false because this is not a standard date
format. After some trial and error I found out strtotime processes input like this:
HHiissYYYY. Whenever the input timestamps have the following conditions the error
occurs: HH less than 24, ii less than 60, and 'ss' less than 61.
In the given example 17 is less than 24, 00 is less than 60, and
39 is less than 61 so the error occurs. In all the following inputs the function works
as expected:
```
2500394677
1760394677
1700614677
```
This isn't a PHP 8 issue and as far as I tested it exists in all versions(5.6, 7.4, 8). I would
be happy to help if needed.
### PHP Version
8.0.30
### Operating System
_No response_