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 LifeCycler { function before() { echo "before!\n"; } function after() { echo "after!\n"; } }); $lc->run(function() { echo "running!\n"; });
Output for 7.0.0 - 7.2.0
Fatal error: class@anonymous cannot implement LifeCycler - it is not an interface in /in/FRZt3 on line 23
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/FRZt3 on line 23
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/FRZt3 on line 9
Process exited with code 255.