8000 Update http_kernel_controller_resolver.rst by wolkenheim · Pull Request #16496 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Update http_kernel_controller_resolver.rst #16496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update http_kernel_controller_resolver.rst
I stumbled upon an exception:  Uncaught TypeError: LeapYearController::index(): Argument #1 ($year) must be of type int, array given, called in /var/www/web/front.php on line 32 and defined in /var/www/src/routes.php:10

This makes sense: getArguments() return indeed an array with the parameters. The index method in the LeapYearController does not expect an array at all. (new LeapYearController)->index(['year' => 2000]) is wrong, and this is happening here when an array is passed into call_user_func(). 

Fix: use spread operator for array destructuring / unpacking to pass in array values as variables. This is on PHP8.1 btw.
  • Loading branch information
wolkenheim authored Feb 11, 2022
commit 1bc3b45f9f327054e2dbf25b65cd707856621302
4 changes: 2 additions & 2 deletions create_framework/http_kernel_controller_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ resolver from HttpKernel::
$controller = $controllerResolver->getController($request);
$arguments = $argumentResolver->getArguments($request, $controller);

$response = call_user_func_array($controller, $arguments);
$response = call_user_func_array($controller, ...$arguments);

.. note::

Expand Down Expand Up @@ -190,7 +190,7 @@ Let's conclude with the new version of our framework::
$controller = $controllerResolver->getController($request);
$arguments = $argumentResolver->getArguments($request, $controller);

$response = call_user_func_array($controller, $arguments);
$response = call_user_func_array($controller, ...$arguments);
} catch (Routing\Exception\ResourceNotFoundException $exception) {
$response = new Response('Not Found', 404);
} catch (Exception $exception) {
Expand Down
0