3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isWeekend($date) { if ($date instanceof DateTime) { $date = DateTimeImmutable::createFromMutable($date); } return $date->setTime(0,0,0) != $date->modify('this weekday'); } function isWeekendUnixTimestamp($dateValue) { return date('Yz', strtotime($dateValue)) != date('Yz', strtotime($dateValue . ' this weekday')); } echo 'DateTimeInterface Comparison:' . PHP_EOL; $sunday = new DateTimeImmutable('Sunday'); $periods = new DatePeriod($sunday, new DateInterval('P1D'), 6); foreach ($periods as $date) { echo $date->format('D') . ' is' . (isWeekend($date) ? '' : ' not') . ' a weekend' . PHP_EOL; } echo PHP_EOL . 'String Comparison:' . PHP_EOL; foreach ($periods as $date) { echo $date->format('D') . ' is' . (isWeekendUnixTimestamp($date->format('Y-m-d')) ? '' : ' not') . ' a weekend' . PHP_EOL; }
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, 8.3.0 - 8.3.4, 8.3.6
DateTimeInterface Comparison: Sun is a weekend Mon is not a weekend Tue is not a weekend Wed is not a weekend Thu is not a weekend Fri is not a weekend Sat is a weekend String Comparison: Sun is a weekend Mon is not a weekend Tue is not a weekend Wed is not a weekend Thu is not a weekend Fri is not a weekend Sat is a weekend
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 DateTimeInterface Comparison: Sun is a weekend Mon is not a weekend Tue is not a weekend Wed is not a weekend Thu is not a weekend Fri is not a weekend Sat is a weekend String Comparison: Sun is a weekend Mon is not a weekend Tue is not a weekend Wed is not a weekend Thu is not a weekend Fri is not a weekend Sat is a weekend
Output for 4.3.0
Parse error: parse error, unexpected T_STRING in /in/TSAVi on line 5
Process exited with code 255.

preferences:
139.23 ms | 401 KiB | 157 Q