On Fri, Aug 16, 2024 at 1:43 PM John Coggeshall <j...@coggeshall.org> wrote:
>
> Hey all,
>
> I poked around a bit in the Enum RFCs and I could find (maybe I missed) 
> what's up with this:
>
> enum Foo:string implements \Stringable
> {
>     case FOO = 'bar';
>
>     public function __toString() {
>         return $this->value;
>     }
> }
>
> PHP Fatal error:  Enum Foo cannot include magic method __toString
>
> It seems to me that when the enum is a string  it is entirely reasonable to 
> expect __toString()  to work here and support the \Stringable  interface.
>
> Is there a reason I'm missing as to why this is problematic in the engine 
> that's been documented somewhere, or is this an oversight we can look at 
> correcting?
>
> John

As others have said, there are definite objections to
auto-implementing string conversions. I think that opt-in string
conversions are sufficiently different that you would have a shot at
an RFC passing. No guarantees about that, of course!

Reply via email to