Skip to content

Exception when a route name is a parsable number #448

@sorrx

Description

@sorrx

For Symfony 6.2 a valid Route could be #[Route(path: '/{_locale}/404', name: '404')]
When using the string '404' as array key in the route-collection internally PHP converts that to an integer. So the annotated return type of the route collection "array<string, Route>" is no longer true due to PHP working in such way.
In Extractor/ExposedRouteExtractor.php the

preg_match('#^'.$this->pattern.'$#', $name, $matches);

then fails with an Exception, because it expects a string and not an integer as second parameter.

compare symfony/symfony#48722

Easy fix for the FOSJsRoutingBundle would be a typecast

preg_match('#^'.$this->pattern.'$#', (string)$name, $matches);

which I understand is kind of annoying, given the annotated return-type

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions