Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128635 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 C28521A00BC for ; Thu, 4 Sep 2025 13:57:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756994144; bh=BHf4uv+4zhuCEJsDZ1mFnps7LasL82EyYtqWVyTBZhE=; h=Date:From:To:In-Reply-To:References:Subject:From; b=mdOZ64Yd1h1Y/YImQio7Rtrbv5zeJiv4SEAyR/caT5wCSlOTeeevmugy7Yv5YGgZ0 MbYz8z6Y+PlmuU5433lWp62uEDdZeXTcn5IByRbMSuOQCDX9C0VClO2YCh7krnLZhv EblFjB25Omkjp0MQ+GZXSNh4W3W1QzQXdcf2yXE7HwScsfXuFhyVtJPi8ricQhXj3+ a9TNTaomVnh/febDpT40+4GYhiva7KQZ/MTkUFc6oiNdUKWEB8879iZ2Vh/+DMOmfo WlOYmWOzXX0RHdwEwTRL8bz7E1dKuet9WGDgRNLg1S5ZRjP1qTRU+dvkSJplbmJrFl MApm8OYRk8Lng== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8429618006A for ; Thu, 4 Sep 2025 13:55:43 +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=-1.4 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a6-smtp.messagingengine.com (fhigh-a6-smtp.messagingengine.com [103.168.172.157]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 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 13:55:43 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id D363714002B1 for ; Thu, 4 Sep 2025 09:57:11 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Thu, 04 Sep 2025 09:57:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1756994231; x=1757080631; bh=6Bb4ksa0R/vzmJr28bTZZ bGPtP4UIvRA40oHJfdvddc=; b=Zkdi/X0TieRBWzH+fpENiJfLJ4W1bzbOVGPhB YszkLjgG4xWtmopfdZueIvj9ajaBBtb2gblRtCD1+qkw/16PNL3wvqQR6O/Zufmn smOv27l+egxbFmXrxapOIrM4fgqWGrqPSaQHIz+42XCdFLVQeOCGZqBA3/9WbKCR 9xQBOjcrxZG5ZqESon4GJ8fFH0eKlHA975hZaRMTCEU9zgOG+WwCMHrYBQLyd1GU 8hReDhittMYiz1fHFJIeQ+AcmMKp7AFHjoOkguXYOdYcry4oc+/jqtZVu0FPK+dp ZMi/O23WsiatkSVwLgahC+uqf0Gp3PjwdnAcxPHEmJ/ga6x2w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1756994231; x=1757080631; bh=6 Bb4ksa0R/vzmJr28bTZZbGPtP4UIvRA40oHJfdvddc=; b=oMihVoX4Lmx6EjTDZ syBVYvwsGIvZBxMAZNROesSyokOxha8HHdnX8mdIwtMxVMio4ijDmn5mOJm2cT1m qIU/ph7KbOBTvyJMoTohh2TM6CJW5O0Nil+AzKwXByJcyWk6PvVccR42CRxwIawH d3wc7a9tHaHtWs72m4atvl0S1VDiZingTA4wisM0isvn8sYlsu35DIwxNIppgbpw hUyusA1QxcEXfcKlP+SPc5RVUxF6NfkXvZKVcbDWys9pdJBA76wq2oIZE1M9cT5i EFyg+L/Bks9yMLnr8YVXVV7dFrN/d1d/KPPP5Pm6xDjV74Id39atYGGab5AY443i hKAog== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdeiudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhihucfi rghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqeenuc ggtffrrghtthgvrhhnpeffieeivdfhvdeguddttdegteeiueegvefhteehfeeffeetudei tdehtdegjeeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghpthht ohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslh hishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 6BE4E700065; Thu, 4 Sep 2025 09:57:11 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: Am7YhlP0TPtJ Date: Thu, 04 Sep 2025 08:56:51 -0500 To: "php internals" Message-ID: In-Reply-To: <25e79d21-7b7f-4d7f-b5cb-1e9cfd0aa657@varteg.nz> References: <9c875e83-ddc8-4c5c-a368-747bef46e4a2@app.fastmail.com> <25e79d21-7b7f-4d7f-b5cb-1e9cfd0aa657@varteg.nz> Subject: Re: [PHP-DEV] enum flag backed enum Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Wed, Sep 3, 2025, at 7:20 PM, Morgan wrote: > On 2025-09-04 09:23, Marc B. wrote: >>> >>> Attempting to use a backed value that is not a power-of-two would re= sult in a compilation error. Bitwise operations are performed as though = they=E2=80=99re performed on a regular integer. >>> >>> What do you think? >>=20 >> I think what we actually would need is an EnumSet which can be used w= ith any enum but (based on its ordinal) but this would play nicely toget= her with generics `new EnumSet`. >>=20 > > Agreed; using enums-backed-by-powers-of-two is just a way to encode se= ts=20 > of values drawn from an enum (it's a way to enumerate the possible=20 > subsets of a set). It should be possible to have a set of Enum values=20 > for any Enum, rather than break the Enum type concept by exposing=20 > implementation details, and allow sets for some types but not others=20 > depending on how they are serialised. > > A class can be built in userspace as a "SetOfEnum"; or such a class=20 > could be added to the standard library; or even have, for each Enum=20 > declared, an EnumSet (final) class is also implicitly declared. It feels like there's two different related topics here. One is using enums as a way to define a set of bit flags rather than con= stants. I'm not sure if this is necessary, but if so, I'd expect a bit = more automation than the initial proposal here. The statement that bitw= ise operations would fall back to integer ops makes me think it falls in= to the "fancy constants" category we have tried to avoid. The other is enum sets, which I am very much in favor of but designing t= hose in a clean way is non-trivial. My collections research with Derick= a while back included a `Set` type, which also supported operator overr= ides for the |, <, <=3D, -, and other operators, so it did effectively g= ive a very nice enum set syntax. Whether that is the optimal approach o= r not is unclear. But an Enum Set feature should work with any enum. (= And of course runs into the eternal generics question.) So, Rob, which one are you really talking about? --Larry Garfield