php-src icon indicating copy to clipboard operation
php-src copied to clipboard

DateTime modify function backward compatibility break on 8.2

Open pkusmierczyk opened this issue 3 years ago • 2 comments

Description

The following code:

<?php
$modifiedDate = (new DateTime('2023-01-17'))->modify(sprintf('+%s days', $days))->format('Y-m-d');

Resulted in this output: For values of $days lower than 0 results are incorrect (according to version 8.1). If value is -1 we get

'2023-01-18'

But I expected this output instead:

'2023-01-16'

PHP Version

8.2

Operating System

Ubuntu 20.04

pkusmierczyk avatar Jan 17 '23 11:01 pkusmierczyk

@pkusmierczyk I think that would be the same as here https://github.com/php/php-src/issues/9950, so it is documented BC (via https://github.com/php/doc-en/commit/ef51b1ce007349e7ff415ec5c707f1b5a73aba27) "number symbols in relative formats no longer accept multiple signs, e.g. +-2"

pospjan avatar Jan 17 '23 12:01 pospjan

Yes, its the same, I couldn't find anything similar before so I have created a new issue

pkusmierczyk avatar Jan 17 '23 12:01 pkusmierczyk