3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('America/New_York'); class Block { private $start; private $end; private $callback; public function __construct($start, $end, callable $callback) { $this->start = $start; $this->end = $end; $this->callback = $callback; } public function check($time) { return $time > strtotime($this->start) && $time > strtotime($this->end); } public function invoke() { call_user_func($this->callback); } } $blocks = [ new Block('16:00:00', '18:00:00', function () { echo 'Foo!'; }), new Block('18:00:00', '20:00:00', function () { echo 'Bar!'; }), new Block('20:00:00', '22:00:00', function () { echo 'Qux!'; }), ]; while (true) { foreach ($blocks as $block) { if ($block->check(time())) { $block->invoke(); } } sleep(1); }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0
Foo!Foo!Foo!
Process exited with code 137.
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/bMMTF on line 23
Process exited with code 255.

preferences:
121.49 ms | 401 KiB | 162 Q