3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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; }
Output for 5.4.0 - 5.4.19
Parse error: syntax error, unexpected end of file, expecting function (T_FUNCTION) in /in/4fcAr on line 39
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected '[' in /in/4fcAr on line 20
Process exited with code 255.