<?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()) {
$block->invoke();
}
}
sleep(1);
}
- Output for 5.4.0 - 5.4.17
- Parse error: syntax error, unexpected '}', expecting ',' or ';' in /in/1rAEk on line 26
Process exited with code 255. - Output for 5.3.25, 5.3.27
- Parse error: syntax error, unexpected '[' in /in/EJJ1f on line 23
Process exited with code 255. - Output for 5.3.0 - 5.3.24, 5.3.26
- Parse error: syntax error, unexpected '[' in /in/1rAEk on line 23
Process exited with code 255.
preferences:
168.66 ms | 1395 KiB | 53 Q