Description
Symfony version(s) affected
6.3.0-BETA3
Description
Hi,
In documentation is an example with optional nullable string parameter (?string $theme = null).
Symfony has allowed to map route parameters to controller arguments since its first version. In Symfony 6.3 you will also be able to map query string parameters to specific controller arguments. To do so, use the new #[MapQueryParameter] attribute:
public function indexAction(
#[MapQueryParameter] array $ids,
#[MapQueryParameter] string $firstName,
#[MapQueryParameter] bool $required,
#[MapQueryParameter] int $age,
#[MapQueryParameter] string $category = '',
#[MapQueryParameter] ?string $theme = null,
)
If the query string of the incoming request is /?ids[]=1&ids[]=2&firstName=Ruud&required=3&age=123, this code will make the controller arguments to have these values:
$ids = ['1', '2']
$firstName = "Ruud"
$required = false
$age = 123
$category = ''
$theme = null
I test similar example on v6.3.0-BETA3 on my application but nullable query string parameter doesn't work.
#[Route(path: '/')]
public function indexAction(
#[MapQueryParameter] ?string $theme = null
): Response {
return new Response('test');
}
-
GET /?theme
works -
GET /
leads to RuntimeException (Controller "App\Controller\IndexController::indexAction" requires that you provide a value for the "$theme" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.)
How to reproduce
Example: https://github.com/szepczynski/symfony-6.3-map-query-parameter-bug-reproduction/
Possible Solution
No response
Additional Context
No response