3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
With recurrences: start=2012-07-01 00:00:00 Fatal error: Uncaught Error: Call to a member function format() on null in /in/iGAV1:13 Stack trace: #0 {main} thrown in /in/iGAV1 on line 13
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 With recurrences: start=2012-07-01 00:00:00 Fatal error: Uncaught Error: Call to a member function format() on null in /in/iGAV1:13 Stack trace: #0 {main} thrown in /in/iGAV1 on line 13
Process exited with code 255.
Output for 7.1.7 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
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 7.0.0 - 7.0.20, 7.1.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

preferences:
182.79 ms | 403 KiB | 202 Q