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() { return $this->package->$method; }; Closure::bind(f, $this); return $f; } } } $salutationsInstance = new salutations(); $obj = new methodFactory($salutationsInstance); $hello = $obj->getPackageMethod('hello'); $hello();
based on 42O7b
Output for 7.2.0
Warning: Use of undefined constant f - assumed 'f' (this will throw an Error in a future version of PHP) in /in/nRe0s on line 17 Warning: Closure::bind() expects parameter 1 to be Closure, string given in /in/nRe0s on line 17 Notice: Undefined variable: method in /in/nRe0s on line 16 Notice: Undefined property: salutations::$ in /in/nRe0s on line 16
Output for 7.1.0 - 7.1.10
Notice: Use of undefined constant f - assumed 'f' in /in/nRe0s on line 17 Warning: Closure::bind() expects parameter 1 to be Closure, string given in /in/nRe0s on line 17 Notice: Undefined variable: method in /in/nRe0s on line 16 Notice: Undefined property: salutations::$ in /in/nRe0s on line 16
Output for 7.0.0 - 7.0.20
Notice: Use of undefined constant f - assumed 'f' in /in/nRe0s on line 17 Warning: Closure::bind() expects parameter 1 to be Closure, string given in /in/nRe0s on line 17 Notice: Undefined variable: method in /in/nRe0s on line 16 Fatal error: Uncaught Error: Cannot access empty property in /in/nRe0s:16 Stack trace: #0 /in/nRe0s(27): methodFactory->{closure}() #1 {main} thrown in /in/nRe0s on line 16
Process exited with code 255.
Output for 5.4.9 - 5.6.28
Notice: Use of undefined constant f - assumed 'f' in /in/nRe0s on line 17 Warning: Closure::bind() expects parameter 1 to be Closure, string given in /in/nRe0s on line 17 Notice: Undefined variable: method in /in/nRe0s on line 16 Fatal error: Cannot access empty property in /in/nRe0s on line 16
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Fatal error: Call to undefined method Closure::bind() in /in/nRe0s on line 17
Process exited with code 255.