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->getClosure()); 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 Error: Call to undefined method CallableByName::getClosure() in /in/i3uCo:21 Stack trace: #0 /in/i3uCo(15): CallableByName->getOrderedFromNamed(Array) #1 /in/i3uCo(48): CallableByName->invoke(Array) #2 {main} thrown in /in/i3uCo on line 21
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:
58.62 ms | 401 KiB | 8 Q