3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function isWeekend($date) { return $date->format('N') >= 6; } function getDayOffInDaysOffByDate($daysOff, \DateTime $date) { $dayOffInDate = null; foreach ($daysOff as $dayOff) { if ($dayOff->getDate()->format('Y-m-d') == $date->format('Y-m-d')) { $dayOffInDate = $dayOff; } } return $dayOffInDate; } $daysOff = array(new \DateTime('2017-07-03'), new \DateTime('2017-07-04')); $periodStartDate = new \DateTime('today'); $periodStartDate = $periodStartDate->modify('-5 days'); $periodEndDate = new \DateTime('today'); $periodEndDate->modify('+1 day'); $period = new \DatePeriod($periodStartDate, \DateInterval::createFromDateString('1 day'), $periodEndDate); foreach ($period as $date) { echo $date->format('Y-m-d'); echo('\n'); if (getDayOffInDaysOffByDate($daysOff, $date) || isWeekend($date)) { echo('minus'); } }
based on vXqpK
Output for 7.0.0 - 7.2.6
2017-06-30\n Fatal error: Uncaught Error: Call to undefined method DateTime::getDate() in /in/dGYeI:12 Stack trace: #0 /in/dGYeI(30): getDayOffInDaysOffByDate(Array, Object(DateTime)) #1 {main} thrown in /in/dGYeI on line 12
Process exited with code 255.
Output for hhvm-3.15.4
2017-06-30\n Fatal error: Uncaught Error: Call to undefined method DateTime::getDate() in /in/dGYeI:12 Stack trace: #0 /in/dGYeI(30): getDayOffInDaysOffByDate() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
2017-06-30\n Fatal error: Call to undefined method DateTime::getDate() in /in/dGYeI on line 12
Process exited with code 255.