Skip to content

Breaking change : Enums are considered as services by the container #60738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GlucNAc opened this issue Jun 7, 2025 · 1 comment
Open

Breaking change : Enums are considered as services by the container #60738

GlucNAc opened this issue Jun 7, 2025 · 1 comment

Comments

@GlucNAc
Copy link

GlucNAc commented Jun 7, 2025

Symfony version(s) affected

7.3.0

Description

Hello :)

When upgrading to SF 7.3, I encountred an error with a service having a property typed as an enum in its constructor.

To isolate the problem, I have created a new SF 7.3 project and it is clear that the container consider enum as a service as it tries to instiate it by doing new EnumName().

How to reproduce

Create an enum

<?php

declare(strict_types=1);

namespace App\Enum;

enum DummyEnum
{
    case First;
    case Second;
    case Third;
}

Create a service with that enum as a dependency

<?php

declare(strict_types=1);

namespace App\Service;

use App\Enum\DummyEnum;

final readonly class DummyService
{
    public function __construct(
        private DummyEnum $dummyEnum,
    ) {
    }

    public function getDummyEnum(): DummyEnum
    {
        return $this->dummyEnum;
    }
}

Use that service in order to trigger its compilation in the conainter

<?php

declare(strict_types=1);

namespace App\Controller;

use App\Service\DummyService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class DummyController extends AbstractController
{
    public function __construct(private readonly DummyService $dummyService)
    {
    }

    #[Route('/dummy', name: 'app_dummy')]
    public function __invoke(): Response
    {
        $de = $this->dummyService->getDummyEnum();

        return new Response();
    }
}

Observe the compilation result in Container1Y0gEYe\getDummyControllerService

Image

Possible Solution

No response

Additional Context

No response

@uncaught
Copy link
Contributor

I can confirm, enums are being picked up as service now when imported via wildcards:

services:
  My\Namespace\:
    resource: './**/*.php'

I don't think this was intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants