3v4l.org

run code in 300+ PHP versions simultaneously
<?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');
Output for git.master, git.master_jit, rfc.property-hooks
Ahnold calls foo() Elvis calls bar() Lerhman calls baz() Fatal error: Uncaught InflectionDeceptionException: Say what? in /in/kLdOp:20 Stack trace: #0 /in/kLdOp(43): Inflector->__call('theBreaks', Array) #1 {main} thrown in /in/kLdOp on line 20
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
34.88 ms | 406 KiB | 5 Q