[php-src] Issue #11542: PHP 8.3: DateTime::modify() throws an exception instead of a warning
| From: | ondrejmirtes | Date: | Mon, 26 Jun 2023 20:14:45 +0000 |
| Subject: | [php-src] Issue #11542: PHP 8.3: DateTime::modify() throws an exception instead of a warning | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244821@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11542
Author: ondrejmirtes
### Description
The following code (https://onlinephp.io/c/b4961)
```php<?php
$dt = new DateTime();
$r = $dt->modify('kewk');
var_dump($r);
```
Resulted in this output:
```
Fatal error: Uncaught DateMalformedStringException: DateTime::modify(): Failed to parse time string
(kewk) at position 0 (k): The timezone could not be found in the database in
/home/user/scripts/code.php:4
Stack trace:
#0 /home/user/scripts/code.php(4): DateTime->modify('kewk')
#1 {main}
thrown in /home/user/scripts/code.php on line 4
```
But I expected this output instead:
```
Warning: DateTime::modify(): Failed to parse time string (kewk) at position 0 (k): The timezone
could not be found in the database in /home/user/scripts/code.php on line 4
bool(false)
```
On PHP 8.2 and lower it was possible to call
DateTime::modify($input) with unsanitized
input and shut-up any possible warnings with @ operator:
@$dt->modify($input).
On PHP 8.3, perhaps because of this RFC https://wiki.php.net/rfc/datetime-exceptions,
this situation now throws an exception. This is a BC break and should be patched. This situation
isn't referenced by the RFC so I believe it's an unwanted side effect.
### PHP Version
PHP 8.3 alpha 2
### Operating System
_No response_