symfony / symfony/maker-bundle
Enum type fatal error when passing the enum class in Symfony 7.2.3
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.4k
- Forks
- 427
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 20
Description
I created a new Symfony 7.2.3 project in a dockerized environment and created a Task entity using make:entity command. I just added a title property.
Then I created a TaskStatus enum like so:
# src/Entity/Enum/TaskStatus.php
<?php
namespace App\Entity\Enum;
enum TaskStatus: int
{
case Pending = 0;
case Done = 1;
}
Then, using make:entity again, I edit my Task entity and fill the form:
Class name of the entity to create or update (e.g. FierceKangaroo):
> task
Your entity already exists! So let's add some new fields!
New property name (press <return> to stop adding fields):
> status
Field type (enter ? to see all types) [string]:
> enum
Enum class:
> App\\Entity\\Enum\\TaskStatus
When I press enter, a fatal error is thrown:
Fatal error: Cannot declare enum App\Entity\Enum\TaskStatus, because the name is already in use in /var/www/src/Entity/Enum/TaskStatus.php on line 5
21:26:22 CRITICAL [php] Fatal Compile Error: Cannot declare enum App\Entity\Enum\TaskStatus, because the name is already in use ["exception" => Symfony\Component\ErrorHandler\Error\FatalError^ { …}]
At this point, what I understand is that the enum cannot exists before I try to add it to my entity. But if I delete it and try again, it now says:
[ERROR] Class "App\\Entity\\Enum\\TaskStatus" doesn't exist; please enter an existing full class name.
By the way, I use a php:8.3.17-apache docker image. How am I supposed to use the enum type in my entities? I found nothing in Symfony's docs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported make:entity flow with an existing App\Entity\Enum\TaskStatus enum, then trace how the command handles the supplied enum class. Compare the behavior when the enum exists and when it does not; done means the supported enum workflow no longer produces a fatal redeclaration error and gives a usable response for a missing class.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100