3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); function toDateInterval(string $interval): DateInterval { if (false === ($res = DateInterval::createFromDateString($interval))) { throw new Exception('Invalid string.'); } return $res; } var_dump(toDateInterval('foobar'));

preferences:
107.52 ms | 404 KiB | 5 Q