Re: RFC proposal: values getter in BackedEnum
| From: | Rowan Tommins | Date: | Thu, 09 Feb 2023 16:50:23 +0000 |
| Subject: | Re: RFC proposal: values getter in BackedEnum | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119513@lists.php.net to get a copy of this message | ||
On Thu, 9 Feb 2023 at 16:18, Sergii Shymko <sergey@shymko.net> wrote:
>
> IMO, other variations of array_column() returning a map don't seem to be
> useful in practice.
> Particularly, what is knowing the case name good for? Do you propose to
> resolve it to the case instance like so?
> $case = constant(ExampleEnum::class . '::' . $caseName);
> My understanding is that backed enums serve the purpose of doing the
> mapping.
>
The same argument can be made for your validation examples: the enum is
"doing the mapping" when you use tryFrom.
My opinion on this probably comes from my general opinion of backed enums -
to me, the opaque case object is primary, and the "value" is just an
arbitrary piece of data attached. I would have preferred to be able to
attach any number of such properties, e.g.
Options::verbose->longArgumentName, Options::verbose->shortArgumentName.
Regards,
--
Rowan Tommins
[IMSoP]