3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on su8MU
Output for 5.6.7 - 7.3.0beta1
ok1ok26
Output for 5.4.0 - 5.5.35
Parse error: syntax error, unexpected '.', expecting variable (T_VARIABLE) in /in/Ud0NT on line 18
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '.', expecting T_VARIABLE in /in/Ud0NT on line 18
Process exited with code 255.