Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118074 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42903 invoked from network); 23 Jun 2022 13:42:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jun 2022 13:42:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C23D9180504 for ; Thu, 23 Jun 2022 08:32:43 -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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 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 (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 23 Jun 2022 08:32:43 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id C7E965C0129 for ; Thu, 23 Jun 2022 11:32:42 -0400 (EDT) Received: from imap52 ([10.202.2.102]) by compute1.internal (MEProxy); Thu, 23 Jun 2022 11:32:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm2; t=1655998362; x=1656084762; bh=koAZlgUnEhCatojTwbXMkyzzp hlBJvLqAmTaXHsZNks=; b=WySCR9eNk1v4mweuVKxANkp4tu3EWa2s6i5BI0Nh4 uMg4A3d9yE9n1hZbnWUw8bCZ6wWIE+UNrrbY5WeyGAntafj5orLw/crpe0ASfC+H 8hFZdgPSk62XZH82O6rkIvqqiLvKI1WAc2KULiHKvHyKToEkkMCbXmx+irPV60sg 49BhfklP0/hBlMPDWZdQY916KsRoDsxPVvS+faEZHhwMkHoVwvKykyLDpCDKP2+B aTkHBo1SjXxS9Ne8HfyEPCsv0tHRBuTnmwPBxY9hv52XwkH+s1C83d+rkik/XVeD boigqQjipU8UYwU/uYCssgKOZuMoNUUbiyqgAXUnHwDhw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1655998362; x=1656084762; bh=k oAZlgUnEhCatojTwbXMkyzzphlBJvLqAmTaXHsZNks=; b=CawXkzgANipmOTFSI KNhZil/vBAfTtHLOBIvZCiZ1Qykf91RtJ30fV0aXUQ/SwhwyZVOt/4wfJCvYNgmO 7HF8Y1E/8p4NfjI66aP1NRWfOvc5QaWVY9nEjjGeoofdY2wxpQtbUctdR6It1YPS yyF+8DgYXE5/PmumLfmv9+J9XeSnhfT4a8Wco6p3F8KGzLUPFQCF4T+IbDD7aGGM ca9MY2/X3H8wmZ09XRDdIr9PztS/XZmBVT+5gfjSI7nBP5RMrEtYa+MsJW2NCXdo xZ62YbMk1z2cQYgDZnWAPV7T/c0OeCLd/bmVxwm2cDktg4wHD9Aa8XSgypKpeQuZ 7S9JQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudefjedgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeeghefgteejheeggfeghfelueeggfdtjeeivedv tefhveeguedufeelhedvteeinecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf ihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 59501C6008B; Thu, 23 Jun 2022 11:32:42 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-713-g1f035dc716-fm-20220617.001-g1f035dc7 Mime-Version: 1.0 Message-ID: <8a60d091-a7fc-4ba9-bbf0-82644c537910@www.fastmail.com> In-Reply-To: References: <9C11261B-B9D0-4342-81EB-60276B3036E5@php.net> <2cee17c0-7b77-4709-94b9-598a4c3d1f49@www.fastmail.com> Date: Thu, 23 Jun 2022 10:32:22 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Auto-implement Stringable for string backed enums From: larry@garfieldtech.com ("Larry Garfield") On Wed, Jun 22, 2022, at 2:31 PM, Alexandru P=C4=83tr=C4=83nescu wrote: > On Wed, Jun 22, 2022 at 8:27 PM Larry Garfield > wrote: > >> >> So I am firmly against making it easier to (mis)use enums in a situat= ion >> where constants are already the superior solution by every metric. T= he >> only argument I see is making case 1, transitioning from a string to = an >> enum for a genuinely limited-case, easier. But in that case, the >> transition is going to have to happen eventually anyway, and that mea= ns the >> type is going to change at some point, and the same BC issue will app= ear, >> just at a different time. Unless the intent is to then never change = the >> type and keep the function incorrectly typed (from the POV that it's >> logically an enum, even though string typed was the best/correct type= for >> years) forever, in which case... use a set of constants. >> >> > > Hi! > I'm with you on what you mentioned here. > > But also, I think the need I understood arises from another case that = is > neither 1 or 2. > When you have two domains the value might need to be represented as a > backed enum in one side and as a string in the other. > As far as I understood, this is the case, with applications that are i= n one > domain wants to have a proper enum for let's say the app roles as the > possible roles are just a limited set. > That application is using another library to configure the ACL using t= hose > roles and this is another domain that does not have a limited value on= the > role representation, it's just a string. > Naturally, you should just transform the enum instance to the string a= nd > that should be done using the value property. But this does not work f= or > configurations done through attribute parameters. > And I think this is the only problem we should fix and that's fixable = by > https://wiki.php.net/rfc/fetch_property_in_const_expressions Yes, I'm planing to vote +1 on that RFC. Although in that case, the sam= e logic for why to use a constant instead still applies. > What you mentioned about developers using enum in the wrong way is > completely true and it's been a long effort for me in explaining this. > I was hoping it would be diminished somehow by increased popularity of > enums, now that they are supported by everyone. But the usages are also > increasing. > > Regards, > Alex I may need to publish a blog post on this issue specifically that Symfon= y and others can point to when people keep asking them to do the wrong t= hing. I fully understand that major frameworks and libraries (Symfony e= t al) are getting the pushback of people trying to do the wrong thing, b= ut the solution should be better educational efforts so people stop tryi= ng to do the wrong thing, not making it easier to do the wrong thing. --Larry Garfield