diff --git a/src/ControlStructure/BlockToken.php b/src/ControlStructure/BlockToken.php index cd718c1..f6d968b 100644 --- a/src/ControlStructure/BlockToken.php +++ b/src/ControlStructure/BlockToken.php @@ -129,18 +129,27 @@ class BlockToken implements ControlStructure { $parameters = []; + foreach((new \ReflectionFunction($method))->getParameters() as $key => $value) { + $name = $value->getName(); + + # Ordered arguments if ( isset($arguments[$key]) ) { - $parameters[ $value->getName() ] = $arguments[$key]; + $parameters[ $name ] = $arguments[$key]; } + # Named arguments + elseif (isset($arguments[$name])) { + $parameters[ $name ] = $arguments[$name]; + } + # Using default value elseif ( $value->isDefaultValueAvailable() ) { - $parameters[ $value->getName() ] = $value->getDefaultValue(); + $parameters[ $name ] = $value->getDefaultValue(); } elseif ( $value->isVariadic() ) { - $parameters[ $value->getName() ] = []; + $parameters[ $name ] = []; } else { - $parameters[ $value->getName() ] = null; + $parameters[ $name ] = null; } } @@ -232,7 +241,7 @@ class BlockToken implements ControlStructure { throw new \InvalidArgumentException("Block '{$this->viewPath}' cannot overwrite 'this' variable."); } - return $classTemplate->picea->inlineBlock($thisProxy ?? $this, $this->viewPath, ...$this->arguments); + return $classTemplate->picea->inlineBlock($this, $this->viewPath, ...$this->arguments); } public function setSlot(string $name, Callable $method) : void