On Mon, Dec 28, 2020 at 10:22 PM Larry Garfield <la...@garfieldtech.com> wrote: > > Hello, Internalians! > > After considerable discussion and effort, Ilija and I are ready to offer you round 2 on enumerations. This is in the spirit of the previous discussion, but based on that discussion a great deal has been reworked. The main change is that Enumeration Cases are now object instances of the Enumeration class rather than their own class. Most of the other changes are knock-on effects of that. > > Of particular note: > > * Cases may not have methods or constants on them. They're just dumb values. > * Enums themselves may have methods, static methods, or constants. > * Traits are supported, as long as they don't have properties. > * The value() method on scalar enums is now a property. > > The full RFC is here, and I recommend reading it again in full given how much was updated. > > https://wiki.php.net/rfc/enumerations > > The implementation is 98% complete; there's still a few lagging bits in reflection, and some opcache bugs that Ilija is still stomping on. > > There are a few outstanding questions listed that we would like feedback on. We're not entirely certain which direction to go with them, for reasons explained in the RFC. Input on those is especially welcome. > > Happy New Year. May it be enumerable. > > -- > Larry Garfield > la...@garfieldtech.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >
Hi! Nice evolution overall. Few notes: - I think ScalarEnum::fromValue() would be more clear than just from() and more in sync with ->value property. - For the class structure you gave an example to illustrate the 'similar' way it is related to class, it would be nice to also mark the class as final. - I agree with no state behavior, at least at this point. However, I would have liked to offer the ability for very easy creation of singleton/multiton patterns using enums, like in Java. - Enums evolve in time and cases are added or sometimes removed. When the storage of the case stays externally (as scalar values or serialized), there could be issues when some of them are removed in the meantime. - for ScalarEnum::from(), for missing values I would guess we will throw an exception, maybe a specific one? Can we mention it in the RFC? - for deserialization, how should it be handled? using an exception as well, same exception as in the previous case. - The allowed_classes option on unserialize() method, I'm guessing it will work with Enums just like every other class, putting an instance of __PHP_Incomplete_Class? - Inheritance would work between enums. But only by eliminating some cases. I can see how enum RedSuites could extend enum Suites without breaking LSP. Not sure if it makes sense to dig on this now. Regards, Alex