- sleep: documentation ( source)
<?php
class Events {
private $events = Array();
function __construct(){}
function bind($eventName,Closure $callback) {
if (!array_key_exists($eventName,$this->events)) {
$this->events[$eventName] = $callback;
}
}
function trig($eventName) {
if(array_key_exists($eventName, $this->events)) {
call_user_func($this->events[$eventName]);
}
}
}
function sayHello() {
print("Hello world.");
}
$e = new Events;
$e->bind('hello',sayHello());
sleep(15);
$e->trig('hello');