Re: [RFC] Enumerations
| From: | Larry Garfield | Date: | Mon, 07 Dec 2020 15:58:00 +0000 |
| Subject: | Re: [RFC] Enumerations | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112460@lists.php.net to get a copy of this message | ||
On Mon, Dec 7, 2020, at 9:56 AM, Rowan Tommins wrote:
> On 07/12/2020 15:26, Larry Garfield wrote:
> > Assuming it's feasible to do, what do people feel about supporting that? IMO,
> > cases(), from(), and values() need to be kept no matter what as they're more self documenting
> > and can be passed around as callables. So the question is just whether we should also try to add
> > casting as an alias to those operations.
>
>
> From my experience answering questions about SimpleXML on Stack
> Overflow, I can confirm that people find magic behaviour of (string)
> hard to discover and understand, and it's not uncommon to see someone
> write $foo->__toString() because they're more familiar with methods.
>
> That's even more true for other casts, e.g. (int)$foo and (float)$foo,
> which can be supported by built-in classes but not userland ones, so are
> even less discoverable.
>
> I can see the appeal of overloading cast syntax, but I would personally
> be on the "just use explicit methods" side.
>
> Regards,
>
> --
> Rowan Tommins (né Collins)
> [IMSoP]
I spoke with Ilija and it turns out it would be really hard to do anyway, so casts are out. I
rescind my request for feedback on that point. :-)
--Larry Garfield