Skip to content

[DependencyInjection] Enums doesn't works when they are binded #44834

Closed
@ismail1432

Description

@ismail1432

Symfony version(s) affected

Any version from 4.4 and PHP 8.1

Description

Use syntax !php/const with an enum as parameter doesn't work properly when you want to bind the parameter.

How to reproduce

<?php
namespace App;

enum Status: string {
    case Draft =  'draft';
    case Deleted =  'deleted';
    case Published = 'published';
}
# services.yaml
parameters:
    my_param: !php/const App\Status::Deleted
services:
    _defaults:
        autowire: true     
        autoconfigure: true
        bind:
            $myParam: '%my_param%'
dd($container->getParameter('my_param')); // is OK output the enum

but

    /**
     * @Route("/foo", name="foo")
     */
    public function index(EntityManagerInterface $entityManager, $myParam): Response

output
image

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