3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Methods { public function doSomething(){ echo 'Did something'; } } class Router { public $methods; public function __construct($methods){ $this->methods = $methods; } public function execute($fn){ return call_user_func($fn->bindTo($this)); } } $router = new Router(new Methods); $router->execute(function(){ echo 'Running the closure'; $this->methods->doSomething(); });
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0alpha1
Running the closureDid something