Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] Support PHP 8.1 enums as route name #44563

Closed as not planned
Closed as not planned
@ThomasLandauer

Description

@ThomasLandauer

Description

I'm trying to avoid strings as Route name, so I've created a Page class that holds consts for it:

abstract class Page
{
    public const HOME = 'SomeUselessStringThatNobodyNeeds';
}

Controller:

#[Route(path: '/', name: Page::HOME)]

I think this would be a perfect use-case for a pure enum:

enum Page
{
    case Home;
}

Controller:

#[Route(path: '/', name: Page::Home)]

Right now, this leads to:

Symfony\Component\Routing\Annotation\Route::__construct(): Argument # 2 ($name) must be of type ?string, App\Enum\Page given

Example

No response

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