3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $firstAvailableCount = 100; $slice = 'weekly'; $countData = array(); $startDateTime = new DateTime("2016-01-10"); $endDateTime = new DateTime("2016-01-12"); fillCountMapPeriod($startDateTime,$endDateTime,$countData,$firstAvailableCount,$slice); function fillCountMapPeriod( DateTime $startDateTime, DateTime $endDateTime, array $countData, $firstAvailableCount, $slice) { if($slice == 'monthly') { $interval = new DateInterval('P1M'); $format = 'm-Y'; $startDateTime = DateTime::createFromFormat($format."-d",$startDateTime->format($format).-"1"); $endDateTime = DateTime::createFromFormat($format."-d",$endDateTime->format($format).-"1"); } else { $interval = new DateInterval('P1W'); $format = 'W-Y'; $startDateTime = DateTime::createFromFormat($format,$startDateTime->format($format)); $endDateTime = DateTime::createFromFormat($format,$endDateTime->format($format)); var_dump($startDateTime); var_dump($endDateTime); } if($startDateTime->format($format) == $endDateTime->format($format)) { var_dump($startDateTime->format($format)); return; } //var_dump($endDateTime); while($startDateTime <= $endDateTime){ var_dump($startDateTime->format("d-".$format)); $startDateTime->add($interval); } }
based on uV9Ft
Output for 7.0.0 - 7.2.0
bool(false) bool(false) Fatal error: Uncaught Error: Call to a member function format() on boolean in /in/h06uQ:28 Stack trace: #0 /in/h06uQ(10): fillCountMapPeriod(false, false, Array, 100, 'weekly') #1 {main} thrown in /in/h06uQ on line 28
Process exited with code 255.
Output for 5.6.8 - 5.6.28
bool(false) bool(false) Fatal error: Call to a member function format() on boolean in /in/h06uQ on line 28
Process exited with code 255.
Output for 5.3.21 - 5.5.35
bool(false) bool(false) Fatal error: Call to a member function format() on a non-object in /in/h06uQ on line 28
Process exited with code 255.