-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Open
Labels
Description
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
Possible Solution
No response
Additional Context
No response
Guuzen