3v4l.org

run code in 300+ PHP versions simultaneously
<?php $modifier = "-1 day"; var_dump((new \DateTimeImmutable("2022-01-01 00:00:00"))->modify($modifier)); // Demonstrates that $modifier is valid $reflClass = new ReflectionClass("DateTimeImmutable"); $brokenDateTime = $reflClass->newInstanceWithoutConstructor(); var_dump($brokenDateTime); var_dump($brokenDateTime->modify($modifier));
Output for 8.3.0 - 8.3.7
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-12-31 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (0) { } Fatal error: Uncaught DateObjectError: Object of type DateTimeImmutable has not been correctly initialized by calling parent::__construct() in its constructor in /in/bKkgl:8 Stack trace: #0 /in/bKkgl(8): DateTimeImmutable->modify('-1 day') #1 {main} thrown in /in/bKkgl on line 8
Process exited with code 255.
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-12-31 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (0) { } Fatal error: Uncaught Error: The DateTime object has not been correctly initialized by its constructor in /in/bKkgl:8 Stack trace: #0 /in/bKkgl(8): DateTimeImmutable->modify('-1 day') #1 {main} thrown in /in/bKkgl on line 8
Process exited with code 255.
Output for 7.4.0 - 7.4.33
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-12-31 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (0) { } Warning: DateTimeImmutable::modify(): The DateTime object has not been correctly initialized by its constructor in /in/bKkgl on line 8 bool(false)

preferences:
121.56 ms | 402 KiB | 123 Q