3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getDiffInHours(\DateTime $earlierDate, \DateTime $laterDate) { $utc = new \DateTimeZone('UTC'); //First convert to UTC to avoid missing hours due to DST etc $earlierDate->setTimezone($utc); $laterDate->setTimezone($utc); $diff = $earlierDate->diff($laterDate); return 24 * $diff->days + $diff->h; } $earlierDate = new \DateTime(); $laterDate = new \DateTime('+ 31 hours'); $hours = getDiffInHours($earlierTime, $laterTime); var_dump($hours, $earlierTime, $laterTime);
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $earlierTime in /in/GEJS0 on line 15 Warning: Undefined variable $laterTime in /in/GEJS0 on line 15 Fatal error: Uncaught TypeError: getDiffInHours(): Argument #1 ($earlierDate) must be of type DateTime, null given, called in /in/GEJS0 on line 15 and defined in /in/GEJS0:2 Stack trace: #0 /in/GEJS0(15): getDiffInHours(NULL, NULL) #1 {main} thrown in /in/GEJS0 on line 2
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
44.4 ms | 402 KiB | 8 Q