3v4l.org

run code in 150+ 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();
Output for 5.3.0 - 5.4.17
Parse error: syntax error, unexpected '<' in /in/4WVku on line 4
Process exited with code 255.