3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Undefined constant "sayHello" in /in/VtDEd:26 Stack trace: #0 {main} thrown in /in/VtDEd on line 26
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
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.0.20, 7.1.0 - 7.1.20
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.5.24 - 5.5.35, 5.6.8 - 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.

preferences:
194.16 ms | 402 KiB | 183 Q