3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class salutations { public function hello() { return "Hello World!"; } } class methodFactory { public function __construct($instance) { $this->package = $instance; } public function getPackageMethod($method) { if (method_exists($this->package, $method)) { $f = function() use ($method) { return $this->$method(); }; $f->bindTo($this); return $f; } } } $salutationsInstance = new salutations(); $obj = new methodFactory($salutationsInstance); $hello = $obj->getPackageMethod('hello'); echo $hello();
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined method methodFactory::hello() in /in/mrEIL:16 Stack trace: #0 /in/mrEIL(27): methodFactory->{closure}() #1 {main} thrown in /in/mrEIL on line 16
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Fatal error: Call to undefined method methodFactory::hello() in /in/mrEIL on line 16
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Fatal error: Call to undefined method Closure::bindTo() in /in/mrEIL on line 17
Process exited with code 255.