Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128618 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 38ACB1A00BC for ; Wed, 3 Sep 2025 21:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756934539; bh=uE+zj966TSV2xGDAXwvd0vsUIjgq0UBOdInQdfVwAL8=; h=Date:From:To:Subject:In-Reply-To:References:From; b=G9zzeNiSX5O1aX58vUY6RaW/teNMhy3/a37zGDFivYBcjm0iNmowARTGB1VbDtpcz 90TovMxitNRkwnYNZ42T2Qw/Q6VWBjMWs7cBAaLSRW2II7wBMHBqW+uqlcLB3xCU0+ kq6ZCkmUR+TgcaUp2jNUy72DdMxaWimOF1SFN5AYOr6XZHvj/kiiAt4VAy1G42sy+F fmf5OT/JGKLjHDxWCwnhibeJ3+YrXSQxD571wPwVxaTHLDaCFagw7q/JE9vX7nMHQa H4aQZbVMUdM3ecU0xUsNb4fNc+vgUrvtZQR3FS3rwL24vlc2NRazfwlkmqrj4zULhu 0xqE+7xw9Scig== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7340618003F for ; Wed, 3 Sep 2025 21:22:15 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mout-y-111.mailbox.org (mout-y-111.mailbox.org [91.198.250.236]) (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 ; Wed, 3 Sep 2025 21:22:14 +0000 (UTC) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-y-111.mailbox.org (Postfix) with ESMTPS id 4cHFwC6Wr4z9ySm for ; Wed, 3 Sep 2025 23:23:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mabe.berlin; s=MBO0001; t=1756934620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YDjPlwgxzKv4y4gQfagP2YfgI/6GZ/P8F/6i3iHYsHs=; b=v/YpWpQ4rV+jPRnLCsCNngHBP3yuM0ArvD7cmAPmRm9W6UktDSVdzy0IrnXQ/e6V2NYqwY uI9aLTsTWs6JXtOy0dkMxjlspHqg/jIPtoE9zjkvZV7eBYNvThZSrE65MtOlooDhiFHFZi j03+iSILrJFThI2k5oaCbeB4azURkVAlgI0QaWgpXwFm+YKfqPV19R09WosqVDmS+A8nwW 1x2iLYaPVGQ6CyiFfkfIHG/6k48Eay5Pa6Sqb1cKP6s5a3uX3XfS5AYQKeyvNvB81zZZqn 22wLWl/in0W3iPmYGdF4n2JOCaC4eOna05Ne3GmlY31RDqZKyGKWvJvxPzOm4g== Date: Wed, 03 Sep 2025 23:23:38 +0200 To: internals@lists.php.net Subject: Re: [PHP-DEV] enum flag backed enum In-Reply-To: <9c875e83-ddc8-4c5c-a368-747bef46e4a2@app.fastmail.com> References: <9c875e83-ddc8-4c5c-a368-747bef46e4a2@app.fastmail.com> Message-ID: Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: marc@mabe.berlin ("Marc B.") Hi Rob, Am 3=2E September 2025 22:44:58 MESZ schrieb Rob Landers : >Hello internals, > >I would like to propose a new type of backed enum: flag=2E This is an int= eger-backed enum that requires power-of-two values that can be combined wit= h the bitwise operators to be used as flags=2E > >In some core functions, it might look like this: > >enum JSON_FLAG: flag { > case None =3D 0; > case ThrowOnError =3D 0x1 << 1; > // etc=2E > case PrettyPrint =3D 0x01 << 4; > // etc=2E >} > >function json_decode(string $data, bool $assoc =3D false, int $depth =3D = 512, JSON_FLAG|int $options =3D JSON_FLAG::None) {} > >json_decode($data, options: JSON_FLAG::ThrowOnError | JSON_FLAG::PrettyPr= int); > >Note that the goal here isn=E2=80=99t so much to save typing space, as it= is to provide easier discoverability through IDEs, better type safety, and= better ergonomics in the language overall=2E > >Attempting to use a backed value that is not a power-of-two would result = in a compilation error=2E Bitwise operations are performed as though they= =E2=80=99re performed on a regular integer=2E > >What do you think? I think what we actually would need is an EnumSet which can be used with a= ny enum but (based on its ordinal) but this would play nicely together with= generics `new EnumSet`=2E > >I couldn=E2=80=99t find any similar proposals (listed on the RFC page) be= fore proposing this on the list, so if you=E2=80=99re working on this, plea= se speak up; I=E2=80=99d like to join forces=2E > >=E2=80=94 Rob Marc