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)) { return $this->package->$method(); } } } $salutationsInstance = new salutations(); $obj = new methodFactory($salutationsInstance); $hello = $obj->getPackageMethod('hello'); $hello();
based on NdjRF
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function Hello World!() in /in/u6oX3:25 Stack trace: #0 {main} thrown in /in/u6oX3 on line 25
Process exited with code 255.
Output for 5.3.19 - 5.6.28
Fatal error: Call to undefined function Hello World!() in /in/u6oX3 on line 25
Process exited with code 255.