Skip to content
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

[PHP82] DateTime modify does not work with addition of minus values #9950

Closed
shyim opened this issue Nov 14, 2022 · 7 comments
Closed

[PHP82] DateTime modify does not work with addition of minus values #9950

shyim opened this issue Nov 14, 2022 · 7 comments

Comments

@shyim
Copy link

shyim commented Nov 14, 2022

Description

The following code:

<?php
$a = (new \DateTimeImmutable('2022-05-01 22:00:00'))->modify('+-30 seconds');

var_dump($a);

Resulted in this output:

Adds 30 seconds

But I expected this output instead:

Should substract 30 seconds like before

https://3v4l.org/6eMQj

It did work before RC3. I am not sure if this is intended or not 😅

PHP Version

PHP 8.2.0 RC6

Operating System

macOs Ventura 13.1 Beta 2

@shyim shyim changed the title DateTime modify does not work with addition of minus values [PHP82] DateTime modify does not work with addition of minus values Nov 14, 2022
@derickr
Copy link
Contributor

derickr commented Nov 14, 2022

You are right that this is a change, but it is expected and on purpose to fix another bug: derickr/timelib@44cfe97 / derickr/timelib#124

It now picks the first sign that it finds... although perhaps it should warn on the second sign. In any case, the workaround is to change the +- to just - in your code.

@derickr
Copy link
Contributor

derickr commented Nov 30, 2022

FWIW, the original behaviour was pretty much a bug, so I don't think we need to do anything here, and hence I'm closing this issue.

@aquavark
Copy link

@derickr I know you closed this, but I just wanted to add that this change also affected strtotime, which broke applications under test in 8.2 in a non-obvious manner (caused duplication of dates in a dynamic built array that then caused data overwriting) and I couldn't find it listed as a PHP 8.2 breaking change anywhere. I've requested to see if PHPStan or PHPCompatibility (for codesniffer) can help detect this as a breaking change. As it was accepted methodology previously (albeit not to the written standard, I accept that) it may cause other breakages that are non-obvious.

@cmb69
Copy link
Contributor

cmb69 commented Jan 11, 2023

Documented as php/doc-en@cf220d0.

@aquavark
Copy link

The other variation, -+, is also no longer possible in 8.2 but worked (in the mathematical sense) in PHP versions from somewhere in PHP5 up to PHP8.1 as well (not that it's likely to happen in most code, but was possible if you were [un]suitably minded).

@cmb69
Copy link
Contributor

cmb69 commented Jan 13, 2023

@aquavark, done with php/doc-en@ef51b1c.

@aquavark
Copy link

Appreciate the update. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants