3v4l.org

run code in 500+ PHP versions simultaneously
<?php class MyDateTimeImmutableMidnightUTC extends \DateTimeImmutable { public function __construct(string $datetime) { parent::__construct($datetime, new \DateTimeZone('UTC')); $time = $this->format('H:i:s'); if ($time !== '00:00:00') { throw new RuntimeException("Midnight UTC datetime called with a non-midnight time! datetime: $datetime time: $time"); } } } new MyDateTimeImmutableMidnightUTC('2000-01-01 00:00'); new MyDateTimeImmutableMidnightUTC('2000-01-01 00:10');
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.7
Fatal error: Uncaught RuntimeException: Midnight UTC datetime called with a non-midnight time! datetime: 2000-01-01 00:10 time: 00:10:00 in /in/UdMcb:8 Stack trace: #0 /in/UdMcb(14): MyDateTimeImmutableMidnightUTC->__construct('2000-01-01 00:1...') #1 {main} thrown in /in/UdMcb on line 8
Process exited with code 255.

preferences:
96.16 ms | 1303 KiB | 4 Q