On Tue, 21 Jun 2022 at 23:47, Nicolas Grekas <nicolas.grekas+...@gmail.com>
wrote:

> Hi everyone!
>
> I'd like to open a discussion on this RFC, to auto-implement Stringable for
> string-backed enums:
> https://wiki.php.net/rfc/auto-implement_stringable_for_string_backed_enums
>


Hi Nicolas,

Like others, I'm lukewarm on this - but then I've always been lukewarm on
both Backed Enums and __toString

For me, the big value of an enum is as a value that is never equal to
anything but itself, so the idea of MyEnum::Foo == 'foo' evaluating to true
feels instinctively wrong to me.

Meanwhile on the string side, I feel like most objects have more than one
string representation, so "blessing" one makes little sense. Taking the
example of permissions given in the PR discussion, what if you need to pass
these same permissions to two different libraries, which have different
format requirements?

However, we DO have backed enums, and people clearly want to use them for
this scenario, so I'm tentatively OK with allowing them to do so, since I
can just use a non-backed enum to get my preferred "style".

Derick raises a good point about it not working for int-backed enums,
though. What if, rather than implementing __toString() as such, we
implemented internal cast handlers for either string or int, depending on
the backing value? (Other internal objects do have this ability, e.g. GMP
and SimpleXMLElement)

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to