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->package->$method; }; Closure::bind($f, $this); return $f; } } } $salutationsInstance = new salutations(); $obj = new methodFactory($salutationsInstance); $hello = $obj->getPackageMethod('hello'); $hello();
based on 6XsFL
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function methodFactory::{closure}(), 0 passed in /in/JN0Ib on line 27 and exactly 1 expected in /in/JN0Ib:16 Stack trace: #0 /in/JN0Ib(27): methodFactory->{closure}() #1 {main} thrown in /in/JN0Ib on line 16
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Warning: Missing argument 1 for methodFactory::{closure}(), called in /in/JN0Ib on line 27 and defined in /in/JN0Ib on line 16 Notice: Undefined variable: method in /in/JN0Ib on line 16 Fatal error: Uncaught Error: Cannot access empty property in /in/JN0Ib:16 Stack trace: #0 /in/JN0Ib(27): methodFactory->{closure}() #1 {main} thrown in /in/JN0Ib on line 16
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Warning: Missing argument 1 for methodFactory::{closure}(), called in /in/JN0Ib on line 27 and defined in /in/JN0Ib on line 16 Notice: Undefined variable: method in /in/JN0Ib on line 16 Fatal error: Cannot access empty property in /in/JN0Ib on line 16
Process exited with code 255.