[php-src] Issue #8217: new DateTime("@".$timestamp) should not crash (throws fatal error) with empty timestamp
| From: | PepeLopez | Date: | Fri, 18 Mar 2022 12:37:58 +0000 |
| Subject: | [php-src] Issue #8217: new DateTime("@".$timestamp) should not crash (throws fatal error) with empty timestamp | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240404@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8217
Author: PepeLopez
### Description
When creating a DateTime object with @ + timestamp (e.g. @123987139) the date is forced to UTC.
That works fine.
**Working Code:**
$timestamp =123987139;
$date = new DateTime("@".$timestamp); // @ Forcing to UTC
However, if the timestamp is empty, php will throw an fatal error like
"PHP Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (@)
at position 0 (@): Unexpected character in ..."
**Non-working Code:**
unset($timestamp) ;
$date = new DateTime("@".$timestamp); // @ Forcing to UTC
**Actual behaviour:**
Script throws fatal error, resulting in error 500, whole script stops
**Desired behavior:**
Throwing just a warning or nothing, returned value should be 0 or false, _script continues_