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($method) { return $this->$method; }; Closure::bindTo($f, $this->package); return $f; } } } $salutationsInstance = new salutations(); $obj = new methodFactory($salutationsInstance); $hello = $obj->getPackageMethod('hello'); $hello();
based on f1euu
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Non-static method Closure::bindTo() cannot be called statically in /in/eUqXr:17 Stack trace: #0 /in/eUqXr(26): methodFactory->getPackageMethod('hello') #1 {main} thrown in /in/eUqXr on line 17
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Fatal error: Non-static method Closure::bindTo() cannot be called statically, assuming $this from incompatible context in /in/eUqXr on line 17
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Fatal error: Call to undefined method Closure::bindTo() in /in/eUqXr on line 17
Process exited with code 255.