3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php date_default_timezone_set('UTC'); function get_pickup_time($str_cutoff_time, $int_flags = 0) { if (!preg_match('#^\d{2}:\d{2}$#', $str_cutoff_time)) { throw new \LogicException('Cutoff time must be expressed in 24 hour hh:mm format'); } $obj_now = new DateTime('next saturday 12:00'); $int_today = (int)$obj_now->format('N'); $int_add_days = 0; // cutoff time - 2 hr pickup window $obj_pickup_time = DateTime::createFromFormat('H:i', $str_cutoff_time)->sub(new DateInterval('PT2H')); // 2 hr lead time if ($obj_pickup_time->diff($obj_now)->h >= 2) { if (($int_today === 6 && !($int_flags & self::PICKUP_ALLOW_SATURDAY)) || ($int_today === 7 && !($int_flags & self::PICKUP_ALLOW_SUNDAY))) { // we don't deliver today $int_add_days = 8 - $int_today; } } else { if ($int_today === 5 && !($int_flags & self::PICKUP_ALLOW_SATURDAY)) { // today is friday and we don't do saturday $int_add_days = $int_flags & self::PICKUP_ALLOW_SUNDAY ? 2 : 3; } else if ($int_today === 6 && !($int_flags & self::PICKUP_ALLOW_SUNDAY)) { // today is saturday and we don't do sunday $int_add_days = 2; } else { $int_add_days = 1; } } if ($int_add_days > 0) { $obj_pickup_time->add(new DateInterval('P' . $int_add_days . 'D')); } return $obj_pickup_time; } var_dump((new DateTime)->format('Y-m-d H:i'), get_pickup_time('17:00')->format('Y-m-d H:i'));
based on 3HAXF
Output for 5.4.0 - 5.4.34
Fatal error: Cannot access self:: when no class scope is active in /in/9Sa1I on line 19
Process exited with code 255.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/9Sa1I on line 40
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/9Sa1I on line 7 Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/9Sa1I on line 40
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/9Sa1I on line 7 Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/9Sa1I on line 40
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/9Sa1I on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/9Sa1I on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/9Sa1I on line 7
Process exited with code 255.