Re: enum flag backed enum

From: Date: Thu, 04 Sep 2025 00:20:34 +0000
Subject: Re: enum flag backed enum
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-128622@lists.php.net to get a copy of this message
On 2025-09-04 09:23, Marc B. wrote:
Attempting to use a backed value that is not a power-of-two would result in a compilation error. Bitwise operations are performed as though they’re performed on a regular integer. What do you think?
I think what we actually would need is an EnumSet which can be used with any enum but (based on its ordinal) but this would play nicely together with generics new EnumSet<JsonOption>.
Agreed; using enums-backed-by-powers-of-two is just a way to encode sets of values drawn from an enum (it's a way to enumerate the possible subsets of a set). It should be possible to have a set of Enum values for any Enum, rather than break the Enum type concept by exposing implementation details, and allow sets for some types but not others depending on how they are serialised. A class can be built in userspace as a "SetOfEnum"; or such a class could be added to the standard library; or even have, for each Enum declared, an EnumSet (final) class is also implicitly declared.

« previous php.internals (#128622) next »