Skip to content

Support for native PHP enums #9021

Closed
@derrabus

Description

@derrabus

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

PHP 8.1 has introduced native enums to the language.

enum Suit: string {
  case Hearts = 'H';
  case Diamonds = 'D';
  case Clubs = 'C';
  case Spades = 'S';
}

#[Entity]
class Card
{
    #[Column, Id]
    public int $id;

    #[Column]
    public Suit $suit;
}

I'd like to use an enum as type of a property. The ORM should store the enums in a VARCHAR field using the backed value. When hydrating such an entity, the enum should be hydrated properly.

The resulting table card would look like this:

id suit
1 H
2 H
3 S
4 C

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