3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getMonths() { $monthsData = array(); $dateBegin = new \DateTime('2018-05-01'); $dateEnd = new \DateTime('2019-01-01'); while ($date->getTimestamp() < $dateEnd->getTimestamp()) { $date->format('d/m/Y'); $monthsData[] = $date; $date->add(new \DateInterval('P1M')); } ksort($monthsData); return $monthsData; } $data = getMonths(); var_dump($data);
based on gthAH
Output for 7.1.0 - 7.3.0alpha1
Notice: Undefined variable: date in /in/UqcAb on line 10 Fatal error: Uncaught Error: Call to a member function getTimestamp() on null in /in/UqcAb:10 Stack trace: #0 /in/UqcAb(21): getMonths() #1 {main} thrown in /in/UqcAb on line 10
Process exited with code 255.
Output for hhvm-3.22.0
Notice: Undefined variable: date in /in/UqcAb on line -1 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function getTimestamp() on a non-object (null)' in /in/UqcAb:-1 Stack trace: #0 /in/UqcAb(-1): getMonths() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
Notice: Undefined variable: date in /in/UqcAb on line 10 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function getTimestamp() on a non-object (null)' in /in/UqcAb:10 Stack trace: #0 /in/UqcAb(21): getMonths() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Notice: Undefined variable: date in /in/UqcAb on line 10 Fatal error: Call to a member function getTimestamp() on null in /in/UqcAb on line 10
Process exited with code 255.