Skip to content

[Proposal]: Adjust handling of EnumEntry::toString() for backed enums #2107

Description

@stloyd

Describe the Proposal

Right now, EnumEntry::toString() calls will always return a name for any given enum, while it's most of the time a perfect fit, but when you have \BackedEnum, you may expect to get the value aligned to the name, not the name itself.

API Adjustments

    public function toString() : string
    {
        if ($this->value === null) {
            return '';
        }

        // New code
        if ($this->value instanceof \BackedEnum) {
            return (string) $this->value->value;
        }

        return $this->value->name;
    }

Are you intending to also work on proposed change?

Yes

Are you interested in sponsoring this change?

None

Integration & Dependencies

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions