On Wed, Oct 2, 2024, at 7:27 AM, Alexandru Pătrănescu wrote:

> I think my view comes from when I initially dug (15+ years ago) into 
> what an enum in Java is, and learned that it is just a syntactic sugar, 
> and a final class would be generated implementing `Comparable` and 
> extending an abstract class `Enum`.
> 
> And I think in PHP that could be a similar view. And most of the 
> limitations we have are not impossible to create with a standard class.

That is roughly the way enums are implemented in several languages, including 
PHP.  

> I think in time we might get to remove some limitations.
> I, personally, don't agree with the `Stringable` related limitation.

This has been discussed numerous times already. Please don't bring it up here, 
it's not relevant to this thread.

> And also with the limitation on no state. In Java this is the simple 
> way to create a singleton: an enum with one case; and we can't have 
> this in PHP.

That is what we mean by ADTs or Tagged Unions (various names for the same 
thing), and it's something Ilija and I have on the roadmap.  It's been on the 
roadmap since the first enum release, but we deliberately punted it for later 
to keep the initial RFC manageable.  It's also dependent on the pattern 
matching RFC, which hopefully we'll be able to bring up for discussion for 8.5.

> If we remove the limitations, should we reclassify at that point enums 
> as classes?

Enums already are classes.  I don't know what reclassification you're talking 
about.  The RFC is about adding a "get me a list of only those classes that are 
enums" function to PHP.  Changing how Enums behave or are implemented is wildly 
out of scope.

--Larry Garfield

Reply via email to