<?php class Inflector { private $methods = []; public function __construct(array $methods) { $this->methods = $methods; //var_dump($this->methods); } public function __call(string $methodName, $test) { if (isset($this->methods[$methodName])) { return $this->methods[$methodName]($test); } throw new InflectionDeceptionException(); } } class InflectionDeceptionException extends \Exception { public function __construct($message = "Say what?") { return parent::__construct($message); } } $a = new Inflector([ 'foo' => function($val){echo sprintf('%s calls foo()', $val[0] ?? 'none!').PHP_EOL;}, 'bar' => function($val){echo sprintf('%s calls bar()', $val[0] ?? 'none!').PHP_EOL;}, 'baz' => function($val){echo sprintf('%s calls baz()', $val[0] ?? 'none!').PHP_EOL;}, ]); $a->foo('Ahnold'); $a->bar('Elvis'); $a->baz('Lerhman'); $a->theBreaks('Who');
You have javascript disabled. You will not be able to edit any code.