Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123394 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 qa.php.net (Postfix) with ESMTPS id AEE311A009C for ; Wed, 22 May 2024 00:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716338834; bh=SikxmWwl/u7F8JNAaVsqF8NkokHCYqDstrsHTc2SHXo=; h=In-Reply-To:References:Date:From:To:Subject:From; b=fhzo8vA9l/Fud2UzcZ59XFqBfH/uieSKE7rdRFGue0zJkGM4nZfZ39wEoYQFcKDu4 8xqvnyd4uog1rkZn5lFwr/FbSwbY5OjtjGdaw1/XolarEwJzSxtZFqwuZub1PMwZFm 458W8aOjJakH/bCY1XHMiMTIMJTjkbbfFO02ThiVZpt08tMQb5VfSEpZAnG1q+++91 VYtYRTeYW/WDG+4QJlJuRGaYeE5MAnx24WJSbdQ9pE43PTLyTruhriJBXhGcaqGL5b a94YzdZCpAZv2dHIJPx8eLh2UCb0awF6Er2vnF6OKzhEfPWXc/S5owtmUyorYr5Mp7 zCfl3L1I6DbPA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9B97618003C for ; Wed, 22 May 2024 00:47:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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, 22 May 2024 00:47:12 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 8F8851381524 for ; Tue, 21 May 2024 20:46:16 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Tue, 21 May 2024 20:46:16 -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=1716338776; x=1716425176; bh=TqxtiH4aHy1DPpS1Wjx+q R6rpV/KYP0DHvfebOQgTAg=; b=sOjMF2MJhhGWSpGZsXtIgZhP/H2hSsHtnnuhI qa3HcEsGAMIVSPfyovezTnELnp8ff2rLhrIJrLORKnPLxZIYnnIJhUK38S72iYx9 X/aPrhpnzWezBjoPrSTiB7Q2xrj36KRKue+eL51jdndSRqSDUUX4yoT2lSwIMc+Z eVxE5MdkqIJ2XwJuYM2hgk5wtIOvha3uIJxJFMxXa+9Gga24NyIOtl349V6XfKXm iqbfiAWSU7ijZu1y1dbwz8IyigjoLFZewvw6oGHfqdNgZLwUkk1FrTbL5ZeyCRfl Y6VwGjG+GiP6D9mFVETEh92ckm5azFMT668B4n5u4RQdKwR1w== 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1716338776; x= 1716425176; bh=TqxtiH4aHy1DPpS1Wjx+qR6rpV/KYP0DHvfebOQgTAg=; b=k 8GmugDFUAZWmUy0Moy/UMCpDdTQDu8YY/Tgl3F3LMwS2d260e8htJT+kAeHRGCkT qHm0bq+U5pXVfiGcoXda9W0+Ryv0cTmy5pm8+C2pc4eV5gqxvNZceBjiSv4KuFvO +H0mpIemP/uncfvt97t2Gg+98meqoGYxQqUBeIlThfvEk54PwPQD5F6zfraYVaHI zIzDx1pm+JmjJVW5RYUEVksQBXhpgo3nCVSax41BVnYDbpQys3Yn2x6Oc5OYcYer TM/72oX22watPwZdE2NFhbl+g626zfWPIzQhy+nPJdzv7MXL7QjOwtK/1pn2cMgv M1Ij4S+sWENIzyscChiwg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdeifedgfeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 216FB1700093; Tue, 21 May 2024 20:46:16 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-480-g515a2f54a-fm-20240515.001-g515a2f54 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <9c763cee-6524-4423-b95e-6bfff4763d2e@app.fastmail.com> In-Reply-To: <3cac0454-ceb2-449a-8b9a-1fac3f866a9c@scriptfusion.com> References: <99c30f5d-e2f3-4027-a8fc-b3b9c71fb6d1@scriptfusion.com> <1286eed1-c35e-40ec-a6f0-84926c99c911@app.fastmail.com> <3cac0454-ceb2-449a-8b9a-1fac3f866a9c@scriptfusion.com> Date: Tue, 21 May 2024 19:45:55 -0500 To: "php internals" Subject: Re: [PHP-DEV] [Discussion] Implicitly backed enums Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Tue, May 21, 2024, at 6:47 PM, Bilge wrote: > On 22/05/2024 00:31, Larry Garfield wrote:=20 >> I could see an argument for auto-populating the backing value off the= enum name if it's not specified, something like this: enum Options: str= ing { >> case First; // This implicitly gets "First" >> case Second =3D '2nd'; >> }=20 > This seems like a reasonable compromise. In this case, all I need to d= o=20 > is change my enum to a backed enum (suffix `: string`) and I get the=20 > benefits of implicit values. I still like the idea of the same being=20 > possible for non-backed enums, though I imagine that is a product of m= y=20 > na=C3=AFvet=C3=A9, as I do not tend to think of things in the framing = of=20 > (de)serialization. Making it really hard and unnatural for people to use PHP enums as "chea= p named strings/ints" is something we want to keep, because the whole va= lue of enums is that they are their own separate type. A Direction is n= ot a string, it's not an int, it's not an array, it's not a Product, it'= s a Direction. That's the end of it. Databases and HTML don't know fro= m Direction or Product, though, so it has to get serialized down to some= thing for those. For arbitrary objects, you basically have to write you= r own mechanism. (I did.) For enums, one comes built-in to make it mor= e standardized: backed enums. >> I'm not sure if I'd support it myself at the moment=20 > Noted, but I once again find myself needing to ask: why not? Were it u= p=20 > to me, I'd say let's start right now! :) Mainly because I haven't thought it through to see what possible issues = it could cause. It may be safe, or there may be currently-not-obvious i= ssues that would result. That's the sort of thing we'd need to explore. For instance, how useful would it be, given that the casing for an enum = should be CamelCase (per PER-CS), but the serialized string is most ofte= n snake_case, and otherwise lowerCamel? We definitely cannot bake case = folding magic into the behavior. So is it even useful at that point? I= don't know. Maybe. That's what needs to be explored. It's not something I'm planning to work on myself at this point, though = if someone else wanted to dig into it I'm happy to help brainstorm with = them. --Larry Garfield