3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CallableByName { private $closure; public function __construct(\Closure $closure) { $this->closure = $closure; } public function invoke(array $parameters) { return call_user_func($this->closure, $this->getOrderedFromNamed($parameters)); } public function getOrderedFromNamed(array $parameters) { $orderedParameters = []; $functionReflection = new \ReflectionFunction($this->closure); foreach ($functionReflection->getParameters() as $parameterReflection) { /* @var $parameterReflection \ReflectionParameter */ $parameterName = $parameterReflection->getName(); if (isset($parameters[$parameterName])) { $orderedParameters[$parameterName] = $parameters[$parameterName]; continue; } if ($parameterReflection->isDefaultValueAvailable()) { $orderedParameters[$parameterName] = $parameterReflection->getDefaultValue(); continue; } $orderedParameters[$parameterName] = null; } return $orderedParameters; } } $callableByName = new CallableByName(function($foo, $bar, $qux = 'Holy Qux!', $zip = null) { var_dump(get_defined_vars()); }); $callableByName->invoke([ 'bar' => 'Hello', 'foo' => 'World', ]);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /in/TLOW3 on line 15 and at least 2 expected in /in/TLOW3:43 Stack trace: #0 /in/TLOW3(15): {closure}(Array) #1 /in/TLOW3(48): CallableByName->invoke(Array) #2 {main} thrown in /in/TLOW3 on line 43
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:
41.47 ms | 401 KiB | 8 Q