3v4l.org

run code in 300+ 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 8.0.0 - 8.0.10, 8.1rc1 - rc2
2012-07-01 Fatal error: Uncaught Exception: DatePeriod::__construct(): Recurrence count must be greater than 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.2.19 - 7.2.33, 7.3.6 - 7.3.30, 7.4.0 - 7.4.23
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.1.33, 7.2.0 - 7.2.18, 7.3.0 - 7.3.5
2012-07-01 2012-07-01

preferences:
95.66 ms | 530 KiB | 12 Q