3v4l.org

run code in 300+ PHP versions simultaneously
<?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'); } }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 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, 8.3.0 - 8.3.4, 8.3.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 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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.

preferences:
185.23 ms | 402 KiB | 173 Q