It's finally time to make the jump! The below code used to work on PHP 5.6
I move to 7.1, and it's failing. What am I doing wrong?
$expectedToday = new DateTime();
$expectedToday->sub(new DateInterval('PT5H'));
$this->assertEquals($expectedToday, functionThatReturnsDateTimeSuccessfully()));
I get
Failed asserting that two DateTime objects are equal.
--- Expected
+++ Actual
@@ @@
2019-03-15T08:35:21+0000
So functionThatReturnsDateTimeSuccessfully is plainly working.
However, when I comment out the second line
$expectedToday = new DateTime();
// $expectedToday->sub(new DateInterval('PT5H'));
$this->assertEquals($expectedToday, functionThatReturnsDateTimeSuccessfully()));
I get
Failed asserting that two DateTime objects are equal.
--- Expected
+++ Actual
@@ @@
-2019-03-15T13:38:31+0000
+2019-03-15T08:38:31+0000
So my question is - what am I doing wrong? Why does sub appear to empty the contents of the whole DateTime object? If this function's borked why don't they deprecate?
--- UPDATE ---
The same issue does not occur with add. This is just with sub.