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'));
Output for 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Fatal error: Uncaught DateMalformedIntervalStringException: Unknown or bad format (foobar) at position 0 (f): The timezone could not be found in the database in /in/IPOmh:5 Stack trace: #0 /in/IPOmh(5): DateInterval::createFromDateString('foobar') #1 /in/IPOmh(13): toDateInterval('foobar') #2 {main} thrown in /in/IPOmh on line 5
Process exited with code 255.
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29
Warning: DateInterval::createFromDateString(): Unknown or bad format (foobar) at position 0 (f): The timezone could not be found in the database in /in/IPOmh on line 5 Fatal error: Uncaught Exception: Invalid string. in /in/IPOmh:6 Stack trace: #0 /in/IPOmh(13): toDateInterval('foobar') #1 {main} thrown in /in/IPOmh on line 6
Process exited with code 255.

preferences:
127.81 ms | 408 KiB | 5 Q