[php-src] Issue #13386: Ambiguous Interpretation of `+-` in `DateTime::modify` Method Since PHP 8.2

From: Date: Tue, 13 Feb 2024 16:45:31 +0000
Subject: [php-src] Issue #13386: Ambiguous Interpretation of `+-` in `DateTime::modify` Method Since PHP 8.2
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246449@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/13386 Author: Daredzik ### Description Hello, I have noticed a change in the behavior of the DateTime::modify method when using the +- notation in the time modification string. In PHP 8.1 and earlier versions, the expression DateTime::modify('+-10 seconds') was interpreted as subtracting 10 seconds from the given date and time. Starting with PHP 8.2, the same expression seems to be interpreted as adding 10 seconds. This change introduces ambiguity and could potentially lead to backward compatibility (BC) issues in existing applications. Was this change intentional? If so, I suggest adding clear information about this change in the PHP 8.2 release notes to inform developers about the change in interpretation of +- in the DateTime::modify method. This would help avoid potential issues related to unexpected application behavior after updating PHP. If the change was not intended, could we consider reverting to the previous behavior in upcoming PHP releases to ensure consistency and avoid BC issues? The following code: ```php <?php $date = new \Datetime('2023-01-01 10:00:00', new \DateTimeZone('UTC')); $seconds = -100; $date->modify(sprintf('+%s seconds', $seconds)); // u can see its +- 100 seconds input string here echo $date->format('c'); ``` example: https://3v4l.org/Eq07c Resulted in this output: ``` // in PHP 8.1 it was "2023-01-01T09:58:20+00:00" // since 8.2 it's now "2023-01-01T10:01:40+00:00" ``` But I expected this output instead: ``` Fix oraz mention as BC in documentation. ``` ### PHP Version PHP 8.2+ ### Operating System Windows 11 + WSL / Ubuntu

« previous php.bugs (#246449) next »