-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid DateTime::modify with negative offset in PHP 8.2 #10228
Comments
I can confirm the behavioral change: https://3v4l.org/vMf7Q We should probably keep BC here, although |
This was a deliberate change, to work around INT_MAX / INT_MIN issues: https://github.com/derickr/timelib/pull/132/files |
#9950 duplicate #10228 <?php
$now = new DateTimeImmutable(); //Maybe local timezone 2023-01-05
$days = -2;
if($days) {
$string = str_replace(array('++', '+-'), array('+', '-'), '+' . $days);
var_dump($now->modify(str_replace('-', '+', $string) . ' day')->format('Y-m-d')); // Force plus sign
}
$days = 2;
if($days) {
$string = str_replace(array('++', '+-'), array('+', '-'), '+' . $days);
var_dump($now->modify($string . ' day')->format('Y-m-d'));
}
?> |
Oh, indeed, duplicate of #9950. |
FWIW, the behavior matches the docs now: |
Description
DateTime::modify
orDateTimeImmutable::modify
in PHP 8.2 returns invalid result with negative offset.PHP 8.1.14 output:
PHP 8.2.1 output:
PHP Version
PHP 8.2.1
Operating System
Linux Mint 21.1
The text was updated successfully, but these errors were encountered: