3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class E{function r($e, $l){$this->e[$e][] = $l;} function d($e){foreach ($this->e[$e] as $l){$l->o();}}} class Listener { function o() { echo 'hello'; } } $listener = new Listener(); $eventDispatcher = new E(); $eventDispatcher->r('event1', $listener); $eventDispatcher->r('event1', $listener); $eventDispatcher->r('event2', $listener); $eventDispatcher->d('event1');
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
hellohello