Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115608 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95520 invoked from network); 29 Jul 2021 22:56:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jul 2021 22:56:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 498971804D0 for ; Thu, 29 Jul 2021 16:23:59 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.0.0/20 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 29 Jul 2021 16:23:58 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id EF6235C00F0 for ; Thu, 29 Jul 2021 19:23:57 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Thu, 29 Jul 2021 19:23:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=WEz0AD36S0HteOI3w0wkYI7pCmIVtkuDqauyHKf+9 Ls=; b=mamK9BbEKv5A+upA2BEMu/al1jvl3OPI8a27PfoD97auOyfkbdNypUB2C 7+8W4o1Xb4678XFOcOr6cjEDIChQRoCC9WCkBFmNz7r1b0bBjclmSWqbGXNYZxpV euFyfE6LqVm+OCyel5CFrDUgl9oYn7YkxdSiLKoEcfo2aVu+Mm6DMTYubm5wxchW a/69qf02O1RPJQ8SBkIa3+7V95fpG3V7CNkJk7aDK8Gr7coqogZmMy2OSB0rkMMv bT8d9R9xg+VHmRanvqmUjUBsuyVUN8o3cBjThIY+qdzPucxrcAGLDHszzvzyCHlI y01PRAWFa9xIPpVEbdYGpSoP+/Lpw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrheeggddtgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeffjeel feejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id B139AAC0E77; Thu, 29 Jul 2021 19:23:57 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-545-g7a4eea542e-fm-20210727.001-g7a4eea54 Mime-Version: 1.0 Message-ID: <3bd8b20b-de03-499e-9821-9e1758bf5e61@www.fastmail.com> In-Reply-To: <1627596973.707329248@f105.i.mail.ru> References: <1627596973.707329248@f105.i.mail.ru> Date: Thu, 29 Jul 2021 18:23:36 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] PHP 8.1 enum const expressions problem From: larry@garfieldtech.com ("Larry Garfield") On Thu, Jul 29, 2021, at 5:16 PM, =D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB =D0= =9D=D0=B5=D1=81=D0=BC=D0=B5=D1=8F=D0=BD=D0=BE=D0=B2 wrote: >=20 > Hello internals! I apologize if such a discussion has already taken=20= > place, but I didn't find anything like it. > =C2=A0 > When working with enums, I ran into problems that are currently not=20= > resolved.=C2=A0In some cases, enumerations require self references and= =20 > constant arithmetic expressions: > =C2=A0 > enum Example: int > { > =C2=A0 =C2=A0 case A=C2=A0=3D 0b0001; > =C2=A0 =C2=A0 case B=C2=A0=3D 0b0010; > =C2=A0 =C2=A0 case C=C2=A0=3D 0b0100; > =C2=A0 > =C2=A0 =C2=A0 public const EXAMPLE_MASK=C2=A0=3D self::A | self::B; //= <<=C2=A0Invalid expression > =C2=A0 =C2=A0 public const EXAMPLE_MASK2 =3D self::A->value | self::B-= >value; // <<=C2=A0Same > } > =C2=A0 > Similar examples can be taken in the existing PHP=C2=A0code, for examp= le,=20 > for attributes (Attribute::TARGET_ALL)=C2=A0which is a binary mask for= =20 > existing =C2=ABtargets=C2=BB.=C2=A0Thus, if targets=C2=A0for attribute= s were implemented=20 > through enumerations, and not through constants, then it would be=20 > impossible to implement such functionality. > =C2=A0 > In addition, enumeration values are not part of constant expressions,=20= > so implementation through "Example::A->value" is also not available. > =C2=A0 > Can you please tell me, maybe there have already been some discussions= =20 > of this problem?=C2=A0And if not, then maybe we should solve this prob= lem=20 > before PHP=C2=A08.1 release?=C2=A0Since it seems to me that the lack o= f such=20 > functionality is quite critical. What you're describing is enum sets. That is, a value that is itself a = union of two enum values. Those are not supported at this time. It's a= ctually a bit tricky to do, since internally enum cases are not a bit va= lue but an actual full PHP object. So self::A | self::B would be trying= to bitwise-OR two objects, which is of course meaningless. The second doesn't work because technically self::A is an object, not a = constant, so it cannot be used in a constant expression. The only dynam= icness added in 8.1 was for "new" expressions in initializers. The obje= cts don't exist at compile time so they cannot be reduced down to a cons= tant value pre-runtime. I agree the current situation is suboptimal. I don't think anyone is op= posed to enum sets, but they're a non-trivial amount of work to do and w= e haven't figured out how to do them yet. There's no simple way to addr= ess it as as bug, so any larger effort will have to wait for 8.2. --Larry Garfield