3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php interface LifeCycleListener { function before(); function after(); } class LifeCycler { private $listeners = []; public function run(callable $x) { foreach ($this->listeners as $l) $l->before(); $x(); foreach ($this->listeners as $l) $l->after(); } public function addListener(LifeCycleListener $listener) { $this->listeners[] = $listener; } } $lc = new LifeCycler(); $lc->addListener(new class implements LifeCycleListener { function before() { echo "before!\n"; } function after() { echo "after!\n"; } }); $lc->run(function() { echo "running!\n"; });
based on FRZt3
Output for 7.0.0 - 7.2.0
before! running! after!
Output for 5.5.0 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/T1I96 on line 23
Process exited with code 255.