Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123393 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 400161A009C for ; Tue, 21 May 2024 23:47:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1716335325; bh=aY6rZVgr89VvXlVcutYW6cpESzCcK3UZ048z7lHt1EU=; h=Date:Subject:To:References:From:In-Reply-To:From; b=e4SDSZuMfU6s/jM22So82lmbFIxsC+8V9Dy2PNuSWZq5mF/EP4xT3Q6lo1G+sXW4y VC6VPDazFdQJHZ3UWxtvH/mkFycoefeJ4Zxei5zhLcw5KL5F1ko/Ibtxp4HsQAPuF4 Y4ze491NT0OpGt9+c99J6I0+XZiybAFnm/gPOuBQB3EwOCXzsy14ge5csTyAhgGbDT HFnilsT5sB06G9nafKoGZBtdkt1q9TMD/4WA5hyNe2j/RtJPDXXP0QLyctVTUuDFBF Zq86vc4yssESdtorNsTh51OAbyJ3D8kvocT9Y1fvVQQDQF6fFyr4svxOZmSvjVv6qw ikSExdRbzUSnw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6FCF9180A88 for ; Tue, 21 May 2024 23:48:41 +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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,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 mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 ; Tue, 21 May 2024 23:48:40 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-420104e5336so1074585e9.1 for ; Tue, 21 May 2024 16:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scriptfusion-com.20230601.gappssmtp.com; s=20230601; t=1716335264; x=1716940064; darn=lists.php.net; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=0UWxO0l+5CxPp35m2YJgNgPUOcwveh/FrIVe+deSM9Y=; b=0brtARAoIUeBKP1jYy46cdwAamfYACxKx1jvVJupZZOU6lc2WgPWkSvIHX7ZiAQ0+w d+AVsdVgFoVZkhocLLMLPQVDatdLXeA+W0KhJCAdajpvQQVn2qTnHuje4ve6WvgDiqkf bq0ILciEPc5cdRKKbQXBzlUiSIyuPpUnXM3O4Z+2EKYnWJeuHMY8Dxuvm2Jm0bdmHQpk onUnqCJQHjMe4hpNddk3cjOiJflGjadg91DgBztf1YxlMHBduyJ7el7C2zYop3CJgz+d P2RhQlqKWSqT+OlLykb1zTGR9fASWP6SZ79WudSvbJ3BxFeFpva5pwM7vg8NLrN9dN3f i+Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716335264; x=1716940064; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=0UWxO0l+5CxPp35m2YJgNgPUOcwveh/FrIVe+deSM9Y=; b=giIQRZYJR6VpeE3k2GNwGwSQP5hynAw/8jBuwP71iA7G4ftn0KJUyt6fmALaKHBd3q Xgu81UMO/2gfnsm+5aobFOnTt1S5P8zVt89n292gTx8u1VhFfBVGxuC3SdcaNNG3++TI H3WwJw5KCawSgPwQ38U6xGxx+3a5LyGFm0DtV903jU4nwGfCp2mQFJNeMdAXAg8XivSV sDiuDI/hwYQACj5Lo0udxvWI9TUlAF37C4+esS4I0iHqhdOG16R02a9z5wNHkR3LKfHl qid/Hx1b+U9bv7oR3AaaGozUO5YpLU36W68qXQvwBDco7GMwyMciKCJinWKYGGCNovFe 9XHw== X-Gm-Message-State: AOJu0Yyr9kUDvnuCFDz5Iv/X5uXQf8ccAR95h855l0YQgQVFMuYKFB22 iDnJ7ndSV4knYvCMYOjVPw9tf5ZS6J1UC252M93q7PlIId5nCfokTFi7xexjjHpnvp/8jI6tvOC k X-Google-Smtp-Source: AGHT+IGv0kU9YWjwqpkGz0mC9Lt8PWPFRMSIoS2aW6f8ZWvI24Ne4rn06GrHBc1+Vs41IsrlauVYLA== X-Received: by 2002:a05:600c:3ba8:b0:41c:73d:63b3 with SMTP id 5b1f17b1804b1-420fce65550mr3813535e9.3.1716335263735; Tue, 21 May 2024 16:47:43 -0700 (PDT) Received: from ?IPV6:2a01:4b00:bf09:5101:2587:d9b1:339a:a3e9? ([2a01:4b00:bf09:5101:2587:d9b1:339a:a3e9]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-42013bf1a5dsm376461275e9.30.2024.05.21.16.47.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 May 2024 16:47:43 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------PUZYMJZcjljGuxt3Y0s7GWUs" Message-ID: <3cac0454-ceb2-449a-8b9a-1fac3f866a9c@scriptfusion.com> Date: Wed, 22 May 2024 00:47:42 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Discussion] Implicitly backed enums To: internals@lists.php.net References: <99c30f5d-e2f3-4027-a8fc-b3b9c71fb6d1@scriptfusion.com> <1286eed1-c35e-40ec-a6f0-84926c99c911@app.fastmail.com> Content-Language: en-GB In-Reply-To: <1286eed1-c35e-40ec-a6f0-84926c99c911@app.fastmail.com> From: bilge@scriptfusion.com (Bilge) This is a multi-part message in MIME format. --------------PUZYMJZcjljGuxt3Y0s7GWUs Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 22/05/2024 00:31, Larry Garfield wrote: > 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: string { > case First; // This implicitly gets "First" > case Second = '2nd'; > } This seems like a reasonable compromise. In this case, all I need to do is change my enum to a backed enum (suffix `: string`) and I get the benefits of implicit values. I still like the idea of the same being possible for non-backed enums, though I imagine that is a product of my naïveté, as I do not tend to think of things in the framing of (de)serialization. > I'm not sure if I'd support it myself at the moment Noted, but I once again find myself needing to ask: why not? Were it up to me, I'd say let's start right now! :) Aside, I am not at all concerned with integer-backed enums at this juncture, and presume that could be a separate discussion/implementation anyway. Cheers, Bilge --------------PUZYMJZcjljGuxt3Y0s7GWUs Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 22/05/2024 00:31, Larry Garfield wrote:
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: string {
  case First; // This implicitly gets "First"
  case Second = '2nd';
}

This seems like a reasonable compromise. In this case, all I need to do is change my enum to a backed enum (suffix `: string`) and I get the benefits of implicit values. I still like the idea of the same being possible for non-backed enums, though I imagine that is a product of my naïveté, as I do not tend to think of things in the framing of (de)serialization.

I'm not sure if I'd support it myself at the moment

Noted, but I once again find myself needing to ask: why not? Were it up to me, I'd say let's start right now! :)

Aside, I am not at all concerned with integer-backed enums at this juncture, and presume that could be a separate discussion/implementation anyway.

Cheers,
Bilge

--------------PUZYMJZcjljGuxt3Y0s7GWUs--