3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Event { private $eventName; function __construct($eventName){ $this->eventName = $eventName; } public function name() { return $this->eventName; } } class QueueManager { private $registeredHandlers = array(); public function addEventListener($eventName, $handler) { if (!isset($this->registeredHandlers[$eventName]) || !is_array($this->registeredHandlers[$eventName])) $this->registeredHandlers[$eventName] = array(); $this->registeredHandlers[$eventName][] = $handler; } public function dispatch($event, &...$args) { $eventName = $event->name(); if (!$this->registeredHandlers[$eventName]) return; foreach ($this->registeredHandlers[$eventName] as $handler) call_user_func_array($handler, $args); } } $qm = new QueueManager(); $qm->addEventListener('click', function(){echo 'ok1';}); //something like this working $qm->addEventListener('click', function(){echo 'ok2';}); $qm->addEventListener('adding', function(&$x){$x = 5;}); //something like this not working $qm->addEventListener('adding', function(&$x){$x++;}); $qm->addEventListener('adding', function($x){echo $x;}); $clickEvent = new Event('click'); $qm->dispatch($clickEvent); $addingEvent = new Event('adding'); $value; $qm->dispatch($addingEvent, $value);
Output for 5.6.0 - 5.6.38, 7.0.0 - 7.0.32, 7.1.0 - 7.1.24, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
ok1ok26
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 ok1ok26
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '.', expecting variable (T_VARIABLE) in /in/Ud0NT on line 18
Process exited with code 255.

preferences:
240.04 ms | 402 KiB | 335 Q