3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class CommandHandler { public function handle($cmd) { //... $this->eventBus->dispatch($events); } } interface EventBus { public function registerListener(Listener $listener); public function dispatch($events); // foreach $event traverse listeners calling when($event) } abstract class Listener { public function __construct(EventBus $bus) { $bus->registerListener($this); } public function when($event) { // call $this->onEvent() if it exsits } } class SomeListener { public function onSomeEvent($event) { // do something } }
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.1.0 - 7.2.4