3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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');
based on VtDEd
Output for 7.0.0 - 7.2.0
Hello world. Fatal error: Uncaught TypeError: Argument 2 passed to Events::bind() must be an instance of Closure, null given, called in /in/fCQcN on line 26 and defined in /in/fCQcN:7 Stack trace: #0 /in/fCQcN(26): Events->bind('hello', NULL) #1 {main} thrown in /in/fCQcN on line 7
Process exited with code 255.
Output for 5.3.21 - 5.6.28
Hello world. Catchable fatal error: Argument 2 passed to Events::bind() must be an instance of Closure, null given, called in /in/fCQcN on line 26 and defined in /in/fCQcN on line 7
Process exited with code 255.