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');
Output for 7.2.0
Warning: Use of undefined constant sayHello - assumed 'sayHello' (this will throw an Error in a future version of PHP) in /in/VtDEd on line 26 Fatal error: Uncaught TypeError: Argument 2 passed to Events::bind() must be an instance of Closure, string given, called in /in/VtDEd on line 26 and defined in /in/VtDEd:7 Stack trace: #0 /in/VtDEd(26): Events->bind('hello', 'sayHello') #1 {main} thrown in /in/VtDEd on line 7
Process exited with code 255.
Output for 7.0.0 - 7.1.10
Notice: Use of undefined constant sayHello - assumed 'sayHello' in /in/VtDEd on line 26 Fatal error: Uncaught TypeError: Argument 2 passed to Events::bind() must be an instance of Closure, string given, called in /in/VtDEd on line 26 and defined in /in/VtDEd:7 Stack trace: #0 /in/VtDEd(26): Events->bind('hello', 'sayHello') #1 {main} thrown in /in/VtDEd on line 7
Process exited with code 255.
Output for 5.3.21 - 5.6.21
Notice: Use of undefined constant sayHello - assumed 'sayHello' in /in/VtDEd on line 26 Catchable fatal error: Argument 2 passed to Events::bind() must be an instance of Closure, string given, called in /in/VtDEd on line 26 and defined in /in/VtDEd on line 7
Process exited with code 255.