3v4l.org

run code in 300+ PHP versions simultaneously
<?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); } }
Output for 8.3.0 - 8.3.6
bool(false) bool(false) Fatal error: Uncaught Error: Call to a member function format() on false 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 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
bool(false) bool(false) Fatal error: Uncaught Error: Call to a member function format() on bool 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 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
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.5.24 - 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.

preferences:
185.24 ms | 401 KiB | 214 Q