Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] #[MapQueryParameter] Problem with nullable parameters #50339

Copy link
Copy link
Closed
@szepczynski

Description

@szepczynski
Issue body actions

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');
    }
  1. GET /?theme works

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.