[php-src] Issue #10583: Regression in DateTime[Immutable]->modify with invalid unit since 8.1.15 and 8.2.2
| From: | marc-mabe | Date: | Tue, 14 Feb 2023 11:16:27 +0000 |
| Subject: | [php-src] Issue #10583: Regression in DateTime[Immutable]->modify with invalid unit since 8.1.15 and 8.2.2 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243727@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10583
Author: marc-mabe
### Description
The following code: https://3v4l.org/EMU1K
```php
<?php
$dt = new DateTime('2015-01-01 00:00:00+00:00');
var_dump($dt->format('c'));
var_dump($dt->modify('+1 s')->format('c'));
$dt = new DateTimeImmutable('2015-01-01 00:00:00+00:00');
var_dump($dt->format('c'));
var_dump($dt->modify('+1 s')->format('c'));
```
Resulted in this output:
```
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+01:00"
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+01:00"
```
But I expected this output instead:
```
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"
```
As you can see it's modifying the time zone offset from
+00:00 to
+01:00 instead of doing nothing as s is not a valid unit according to https://www.php.net/manual/en/datetime.formats.relative.php.
It's interesting here because s is a common mistake as abbr. of
second & sec where also ms and µs would be
valid (which is another topic) but there is also no documented way of modifying the time zone using
modify and in this particular case it's effectively moving backward instead of
forward.
### PHP Version
PHP 8.1.15 / PHP 8.2.2
### Operating System
Linux