<?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() use ($method) { return $this->$method(); };
$f->bindTo($this->package);
return $f;
}
}
}
$salutationsInstance = new salutations();
$obj = new methodFactory($salutationsInstance);
$hello = $obj->getPackageMethod('hello');
echo $hello();
Deprecated: Creation of dynamic property methodFactory::$package is deprecated in /in/8F9Ji on line 11
Fatal error: Uncaught Error: Call to undefined method methodFactory::hello() in /in/8F9Ji:16
Stack trace:
#0 /in/8F9Ji(27): methodFactory->{closure}()
#1 {main}
thrown in /in/8F9Ji on line 16
Process exited with code 255.
Fatal error: Uncaught Error: Call to undefined method methodFactory::hello() in /in/8F9Ji:16
Stack trace:
#0 /in/8F9Ji(27): methodFactory->{closure}()
#1 {main}
thrown in /in/8F9Ji on line 16
Process exited with code 255.