3v4l.org

run code in 200+ php & hhvm versions
<?php $start = new DateTimeImmutable('2012-07-01'); $end = new DateTimeImmutable('2012-07-31'); $interval = new DateInterval('P7D'); $recurrences = 4; $periodWithRecurrences = new DatePeriod($start, $interval, $recurrences); echo "With recurrences:\n"; foreach ($periodWithRecurrences as $r) { printf("start=%s\n", $periodWithRecurrences->start->format("Y-m-d H:i:s")); printf("current=%s\n", $periodWithRecurrences->current->format("Y-m-d H:i:s")); printf("end=%s\n", $periodWithRecurrences->end ? $periodWithRecurrences->end->format("Y-m-d H:i:s") : "null"); printf("interval=%s\n", $periodWithRecurrences->interval->format("P%r%yY%mM%dDT%hH%iM%sS (%ad)")); printf("recurrences=%s\n", $periodWithRecurrences->recurrences); printf("include_start_date=%s\n", $periodWithRecurrences->include_start_date); break; } $periodWithoutRecurrences = new DatePeriod($start, $interval, $end); echo "\nWithout recurrences:\n"; foreach ($periodWithoutRecurrences as $r) { printf("start=%s\n", $periodWithoutRecurrences->start->format("Y-m-d H:i:s")); printf("current=%s\n", $periodWithoutRecurrences->current->format("Y-m-d H:i:s")); printf("end=%s\n", $periodWithoutRecurrences->end ? $periodWithoutRecurrences->end->format("Y-m-d H:i:s") : "null"); printf("interval=%s\n", $periodWithoutRecurrences->interval->format("P%r%yY%mM%dDT%hH%iM%sS (%ad)")); printf("recurrences=%s\n", $periodWithoutRecurrences->recurrences); printf("include_start_date=%s\n", $periodWithoutRecurrences->include_start_date); break; }
Output for 7.1.7 - 7.2.6
With recurrences: start=2012-07-01 00:00:00 current=2012-07-01 00:00:00 end=null interval=P0Y0M7DT0H0M0S ((unknown)d) recurrences=5 include_start_date=1 Without recurrences: start=2012-07-01 00:00:00 current=2012-07-01 00:00:00 end=2012-07-31 00:00:00 interval=P0Y0M7DT0H0M0S ((unknown)d) recurrences=1 include_start_date=1
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.6
With recurrences: start=2012-07-01 00:00:00 current=2012-07-01 00:00:00 end=null Warning: DateInterval::format(): The DateInterval object has not been correctly initialized by its constructor in /in/iGAV1 on line 15 interval= recurrences=5 include_start_date=1 Without recurrences: start=2012-07-01 00:00:00 current=2012-07-01 00:00:00 end=2012-07-31 00:00:00 Warning: DateInterval::format(): The DateInterval object has not been correctly initialized by its constructor in /in/iGAV1 on line 27 interval= recurrences=1 include_start_date=1
Output for hhvm-3.18.4 - 3.21.0
With recurrences: Without recurrences: Fatal error: Uncaught Error: Cannot access private property DatePeriod::$start in /in/iGAV1:24 Stack trace: #0 {main}
Process exited with code 255.