Skip to content

Same logic in @Route and XML defaults parameter give different results #7335

@Sydney-o9

Description

@Sydney-o9

This code dumps the correct $id variable of type null:

    /**
     * Show user
     *
     * @Route("/show/{id}", name="acme_user_show", defaults={"id"=null}, requirements={"id"="\d+"})
     */
    public function showUserAction($id = null)
    {
        var_dump($id);
    }

whereas the following code gives an $id variable of type string string(4) "null"

    /**
     * Show user
     *
     */
    public function showUserAction($id = null)
    {
        var_dump($id);
    }
    <route id="acme_user_show" pattern="/show/{id}">
        <default key="_controller">AcmeUserBundle:User:show</default>
        <default key="id">null</default>
        <requirement key="id">\d+</requirement>
    </route>

I would assume the 2 to give similar results, is this normal?

Note: I visit the /showUser path to test if $id variable is null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions