Compile Error: Cannot use positional argument after named argument | Symfony 4

Viewed 375
/**
 * @param $name
 * @return Response
 * @Route ("/afficheN/{name}",name="afficheN")
 */
public function afficheName($name){
    return $this->render(view:'student/affiche.html.twig',
        ['n' => $name]);
}
1 Answers

Php 8 added a new feature called named arguments, it allows you to pass input data into a function, based on their argument name instead of the argument order.

It is possible to combine named and ordered arguments, but only if the ordered arguments came first.

To make you code work, you have two options

  1. Use named arguments for all arguments:

    return $this->render(view:'student/affiche.html.twig', parameters:['n' => $name]);

  2. Do not use named arguments at all:

    return $this->render('student/affiche.html.twig', ['n' => $name]);

Here is a link where you can learn more about named arguments

You can also check the php documentation

Related