Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128622 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id F1DEE1A00BC for ; Thu, 4 Sep 2025 00:20:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756945159; bh=LXynCl6vHsk0/AQKaQTZxXJIFHwfz+o7oBwdLkjt7oQ=; h=Date:Subject:To:References:From:In-Reply-To:From; b=NHB+HPn9xe6JDsaZF22hehZc0MwFaoGqJTPsD6KRpkkZq964l+lXkZ43Pb6y9xCvJ UGC6A0OTysteVY3WoGk13oHo5ReBYBu5C/rmUFHfkKEFp57MdlerfPYCQ9XTYN1MdW sYSll/4C3vhLU3/8aYF+nBJs7iZcZarzNUcQ4CKexEIaCao5Tx9X9kI1010Ws35cmR UYsG3hOqAjAeJlkROvGMtm00iUIFag0zSfHcN8quTwTCnG1XuyaQVSUM9SM/VyaQsI ObNIgIS9XTBlq9yYTeR0jbprJ9get6tGBKg0Nz1nWihp3aslNN3E3gVrGjwSmcu8Lj F1qfLWuSBjksA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E3EFB18006C for ; Thu, 4 Sep 2025 00:19:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from franklin.smtp.mailx.hosts.net.nz (franklin.smtp.mailx.hosts.net.nz [43.245.52.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 4 Sep 2025 00:19:16 +0000 (UTC) Received: from 122-57-11-211-adsl.sparkbb.co.nz ([122.57.11.211] helo=[192.168.1.67]) by franklin.smtp.mailx.hosts.net.nz with esmtpsa authed as varteg.nz (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim 4.96) (envelope-from ) id 1utxiT-00Cal8-35 for internals@lists.php.net; Thu, 04 Sep 2025 12:20:42 +1200 Message-ID: <25e79d21-7b7f-4d7f-b5cb-1e9cfd0aa657@varteg.nz> Date: Thu, 4 Sep 2025 12:20:34 +1200 Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] enum flag backed enum To: internals@lists.php.net References: <9c875e83-ddc8-4c5c-a368-747bef46e4a2@app.fastmail.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Hosts-DKIM-Check: none From: weedpacket@varteg.nz (Morgan) 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`. > 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.