run code in 200+ php & hhvm versions
Bugs & Features
<?php <?php trait BindableMethod { public function bindMethod($name, Closure $method, $overwrite = true) { if (method_exists($this, $name)) { return; } if ($overwrite === false && isset($this->$name)) { return; } $this->$name = \Closure::bind($method, $this, $this); } public function __call($method, $args) { if (isset($this->$method) && is_callable($this->$method)) { return call_user_func_array($this->$method, (array) $args); } } } class Foo { use BindableMethod; private $food = 'Tomatoes'; public function getFood() { return $this->food; } } $foo = new Foo(); $foo->bindMethod('changeToPickles', function(){ $this->food = 'pickles'; }); $foo->changeToPickles(); echo $foo->getFood();

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)