3v4l.org

run code in 500+ PHP versions simultaneously
<?php $distance = -10; $dt = new DateTimeImmutable('2024-03-21 12:00:00'); var_dump($dt->modify("-{$distance} hours")); var_dump($dt->modify((-$distance) . " hours"));
Output for 8.1.27 - 8.1.34, 8.2.25 - 8.2.32, 8.3.13 - 8.3.33, 8.4.1 - 8.4.24, 8.5.0 - 8.5.9
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2024-03-21 22:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2024-03-21 22:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 8.2.16 - 8.2.24, 8.3.3 - 8.3.12
object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2024-03-21 02:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2024-03-21 22:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }

preferences:
81.87 ms | 862 KiB | 4 Q