3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyInterval extends DateInterval { public static function instance(DateInterval $di) { $date = array_filter(array( 'Y' => $di->y, 'M' => $di->m, 'D' => $di->d, )); $time = array_filter(array( 'H' => $di->h, 'M' => $di->i, 'S' => $di->s, )); $specString = 'P'; foreach ($date as $key => $value) { $specString .= $value.$key; } if (count($time) > 0) { $specString .= 'T'; foreach ($time as $key => $value) { $specString .= $value.$key; } } return new static($specString === 'P' ? 'PT0S' : $specString); } } $diff = (new DateTime('yesterday'))->diff(new DateTime('tomorrow')); $myDiff = MyInterval::instance($diff); var_dump($myDiff);
Output for git.master, git.master_jit, rfc.property-hooks
object(MyInterval)#1 (10) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(2) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["invert"]=> int(0) ["days"]=> bool(false) ["from_string"]=> bool(false) }

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:
50.27 ms | 401 KiB | 8 Q