Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Support for PHP 8.1 enums #40241

Copy link
Copy link
Closed
@ogizanagi

Description

@ogizanagi
Issue body actions

Description

https://wiki.php.net/rfc/enumerations#backed_enums

Backed enums have scalar equivalents. The Serializer should be able to normalize and denormalize such enums.

Example

class Foo {
    public Suit $suit;
}

$foo = new Foo();
$foo->suit = Suit::Diamonds;
$serialized = $this->serializer->serialize($foo, 'json')
// expected: '{ "suit": "D" }'

$this->serializer->deserialize($serialized, Foo::class);
// expected: Foo->suit === Suit::Diamonds

Should pure enums (no scalar equivalent) be supported as well, by relying on the name property? (Suit::Spades->name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.Serializer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.