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();
Output for 7.0.0 - 7.2.0
Notice: Undefined property: salutations::$hello in /in/NdjRF on line 16 Fatal error: Uncaught Error: Function name must be a string in /in/NdjRF:25 Stack trace: #0 {main} thrown in /in/NdjRF on line 25
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Notice: Undefined property: salutations::$hello in /in/NdjRF on line 16 Fatal error: Function name must be a string in /in/NdjRF on line 25
Process exited with code 255.