Re: String enums & __toString()
| From: | Rowan Tommins [IMSoP] | Date: | Sat, 17 Aug 2024 22:20:40 +0000 |
| Subject: | Re: String enums & __toString() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-125033@lists.php.net to get a copy of this message | ||
On 17 August 2024 21:27:59 BST, John Coggeshall <john@coggeshall.org> wrote:
>
>I don't think it's without purpose... what it should be for is to allow developers to
>make flexible APIs where they can type-hint string|Stringable and the user of the API doesn't
>have to worry about it.
My view is that the user *should* have to think about it - if what the API needs is a string, tell
me that, and I'll pick a method that returns a relevant string.
I also think it's weird that Stringable is a magic implicit interface. If it makes sense at
all, surely it should be a pseudo-type like callable, and also accept int and float values, since
they can be cast to string too.
But maybe I shouldn't have said anything, because I've had this conversation before and it
generally just leads to agreeing to disagree. Plenty of people seem to think __toString and
Stringable are a good idea, so I guess I'll just leave y'all to it.
Regards,
Rowan Tommins
[IMSoP]