Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Support for PHP 8.1 enums #40241

Closed
@ogizanagi

Description

@ogizanagi

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.Serializer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions