3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $oneMonth = new \DateInterval('P1M'); $startDate = date('Y-m-d'); $period = new \DatePeriod($startDate, $oneMonth, 16); foreach($period as $date){ //$date is an instance of \DateTime. I'm just var_dumping it for illustration var_dump($date); }
based on LYQ2J
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Exception: DatePeriod::__construct(): This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments. in /in/1EIKA:4 Stack trace: #0 /in/1EIKA(4): DatePeriod->__construct('2016-03-21', Object(DateInterval), 16) #1 {main} thrown in /in/1EIKA on line 4
Process exited with code 255.
Output for 5.5.0 - 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'DatePeriod::__construct(): This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments.' in /in/1EIKA:4 Stack trace: #0 /in/1EIKA(4): DatePeriod->__construct('2016-03-21', Object(DateInterval), 16) #1 {main} thrown in /in/1EIKA on line 4
Process exited with code 255.
Output for 5.3.0 - 5.4.45
Fatal error: Uncaught exception 'Exception' with message 'DatePeriod::__construct(): This constructor accepts either (DateTime, DateInterval, int) OR (DateTime, DateInterval, DateTime) OR (string) as arguments.' in /in/1EIKA:4 Stack trace: #0 /in/1EIKA(4): DatePeriod->__construct('2016-03-21', Object(DateInterval), 16) #1 {main} thrown in /in/1EIKA on line 4
Process exited with code 255.
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/1EIKA on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/1EIKA on line 4 Fatal error: Class 'DateInterval' not found in /in/1EIKA on line 2
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/1EIKA on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/1EIKA on line 4 Fatal error: Cannot instantiate non-existent class: dateinterval in /in/1EIKA on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/1EIKA on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/1EIKA on line 4 Fatal error: Cannot instantiate non-existent class: dateinterval in /in/1EIKA on line 2