3v4l.org

run code in 200+ PHP versions simultaneously
<?php $start = new DateTimeImmutable('2012-07-01'); $interval = new DateInterval('P1D'); $periodWithRecurrences = new \DatePeriod($start, $interval, $start->add($interval)); foreach($periodWithRecurrences as $date) { echo $date->format('Y-m-d') . \PHP_EOL; } echo \PHP_EOL; $periodWithRecurrences = new DatePeriod($start, $interval, 0); foreach($periodWithRecurrences as $date) { echo $date->format('Y-m-d') . \PHP_EOL; }
Output for 7.2.19 - 7.2.29, 7.3.6 - 7.4.6
2012-07-01 Fatal error: Uncaught Exception: DatePeriod::__construct(): The recurrence count '0' is invalid. Needs to be > 0 in /in/ReWbN:13 Stack trace: #0 /in/ReWbN(13): DatePeriod->__construct(Object(DateTimeImmutable), Object(DateInterval), 0) #1 {main} thrown in /in/ReWbN on line 13
Process exited with code 255.
Output for 7.1.0 - 7.2.18, 7.3.0 - 7.3.5
2012-07-01 2012-07-01