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

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

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

Php 8 添加了名为命名参数的新功能,它允许您根据参数名称而不是参数顺序将输入数据传递给函数。

可以组合命名参数和有序参数,但前提是有序参数在前。

为了让你的代码工作,你有两个选择

  1. 对所有参数使用命名参数:

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

  2. 根本不使用命名参数:

    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