Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127977 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 A09C71A00BC for ; Wed, 9 Jul 2025 16:40:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1752079091; bh=MK+SxRf5sJBDvk6CEEgZcNjpB4VPD0+Yfb5vNm4pMfs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=lkTGiJ5h4orzPlCzAEw/UISTRnz7veM9MYV2aTOmMc4koI8O9dr5QTZdnbOD1+tW9 xUaO/Gntlg+tkJOhRQheyGrRoMbT+86E1a0zoCyVvK4vUWtAb85cxHdbnTr2dgAx3f Q+HmDJZmxV9usnAUHvfF3oo9V+drKVGyeOX/+m3LGX1U2j1ApQLdDwzDwuLLxKPkbZ 3J9GbaTZLMnqY0h0JLUwdtfjMccQoQ/92Ce8xjDRf0kcn6O+szcT/FMxkCCbThxKl7 9/1RiJ9d+o5kxn7B9vUSq7MDEdTrThvGi2h5VAHdnrCwnli7cB3ubmrsQWVDyqLG1N 6rQwaN1jwPgMA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7B8721801D7 for ; Wed, 9 Jul 2025 16:38:10 +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.4 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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, 9 Jul 2025 16:38:10 +0000 (UTC) Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-71101efedabso131357b3.2 for ; Wed, 09 Jul 2025 09:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752079200; x=1752684000; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MK+SxRf5sJBDvk6CEEgZcNjpB4VPD0+Yfb5vNm4pMfs=; b=nBvf/v8jFKKZG8YWHHu+7GMuo6hrSIf3eb2rD4MVYTSKF3HwY8KvVuWc50RwP9ejOV 8X71ud0h/MKgRgEketnqTQojiNYoLJlWSUBYceegPzkXxsTwOoS3FtvI7xmxNp0ojK9F ilAr+HoyzFxWna4z73d44T+VKCmIL37NJ3oE1dz1q857u9rrxyD3v/8vWWQlfdyuv40B v730bjQPRGdFh4vlHyHqYQpwonBq0GjNvC/7ntZnw6rVaFq6n10c9+Mq2JNYA46WTLXN qSngF3+rY9tF4wi3TEC8vFzpj2HFuUsHZBp68prbXSzyO6WgWOI2NlzGu847VBKrUxdn gOUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752079200; x=1752684000; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MK+SxRf5sJBDvk6CEEgZcNjpB4VPD0+Yfb5vNm4pMfs=; b=Hmo3zpJwDPY4dXbZrHB90tLVUf/bTtbCYOXYap61/xVgUg7n9Loup3uaNfX+5WYCre epvX0c84hGhM5GtAqVeXgEHK4u9RVXru8dBYTZLMPjy11apum/XOi4bee35I1oq+BdJ+ Tr2K3jwWjnDsck/QsUsMIndlwaVqzUUl+bXVpysNXtIlOr306f5qJCkmzgMhxD6OTCgm usH1sxLLLHoW1xk5IXn44RKeUFogp6E7NM6XJ3bRYnZNiphRwsnGLQFuHg23VNnzOF14 I8+0Dy+9onyXsYyvEjmtxX2AgomLnfc3tA6vwBQX9xwyTMy6fzuryi5t7QUIBoeUe/Z4 xd4A== X-Gm-Message-State: AOJu0YybPS+fAUGDuDSaZo2xMHQTDgqU4wTfy9z8dynUx3GQVjRdoqwi LZ/t6togDEJR+Ej+QHGv6xwmyWsAasPLGrd3S498UIE+lL/mF9dEH2DTPo6RnykLccdGi1mdplX eouu/qbbPkSJTilyZARQnxYbPMfOgxCc= X-Gm-Gg: ASbGncteoEY0B5EImBoG3/yd4WPw2ulaE8VX6G9x+hEnBpELbZPEn080a4e6rXTHjcO p84Mi60cHKqhb4KHpu9+i/D8/xCnMKzG9yHMn9w5DYVs6cj3lzL8nA2GmJj2Z9gow7ZiH68HMp9 2T9U79kmYFNbB9lWvk/MH92JLI8FJVTQt+VFxAnp2CP4OpUt7um9RK0Y3QjUoU7Gw2nNRQNZZ/Q Q== X-Google-Smtp-Source: AGHT+IFRsgLaGl5fUkG7YYv1Og/OlSOwEIpRDHE4fjRIAtU+FIBbk0W8q7AhNlpGoTbIDmx2Gj2GXpuW7Pn2EVidAnU= X-Received: by 2002:a05:690c:6483:b0:70e:6261:f7f1 with SMTP id 00721157ae682-717b19bfa7fmr20003527b3.7.1752079199510; Wed, 09 Jul 2025 09:39:59 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <5a38b818-8366-4edc-93ab-a147e3a9aec3@app.fastmail.com> In-Reply-To: <5a38b818-8366-4edc-93ab-a147e3a9aec3@app.fastmail.com> Date: Wed, 9 Jul 2025 13:39:23 -0300 X-Gm-Features: Ac12FXxkcZN5z4bFjiL1I5cPWYgUSDISGmct4ALAb3ICQdbdOrJgPosM2RaUpcM Message-ID: Subject: Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums To: Rob Landers Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000004e26a6063981baf9" From: deleugyn@gmail.com (Deleu) --0000000000004e26a6063981baf9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jul 9, 2025 at 1:17=E2=80=AFPM Rob Landers wrot= e: > > Hey Marco, > > I think this relies on whether the =E2=80=9Cnatural value=E2=80=9D of a u= nit enum is a > string or not. It might be, or it might not be. I don=E2=80=99t think you= have a > compelling argument on why it is a string and that string is the name. > Personally, I used int-backed enumerations far more so I would argue that > the natural value is an integer, not a string. I=E2=80=99ve been thinking= of a > =E2=80=9Cquality-of-life RFC=E2=80=9D for obvious enums, for some time no= w. Basically, > backed enums without a value receive the =E2=80=9Cobvious=E2=80=9D value.= So a string > backed enum gets the name, while an int gets the ordered number. > > I think something like that makes more sense than trying to decide what > the =E2=80=9Cnatural value=E2=80=9D of a unit enum is. > > =E2=80=94 Rob > It makes sense that if a Unit Enum were to be given a `value` we would have a hard time defining what type such value should have. This strengthens my desire for Larry's suggestion for String-backed Enums defaulting to their names. That way, we sidestep the issue of the value type of a Unit Enum, we avoid a potential breaking change by introducing a method that could conflict with userland and it also makes it opt-in. By adding `: string` to a Unit Enum, we make the `->value` equivalent to the `->name` and receive the from() implementation for it. It's currently undeniable that a Unit Enum name is a string. --=20 Marco Deleu --0000000000004e26a6063981baf9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Wed, Jul 9, = 2025 at 1:17=E2=80=AFPM Rob Landers <rob@bottled.codes> wrote:

<= /div>
Hey Marco,

I think this relies on whethe= r the =E2=80=9Cnatural value=E2=80=9D of a unit enum is a string or not. It= might be, or it might not be. I don=E2=80=99t think you have a compelling = argument on why it is a string and that string is the name. Personally, I u= sed int-backed enumerations far more so I would argue that the natural valu= e is an integer, not a string. I=E2=80=99ve been thinking of a =E2=80=9Cqua= lity-of-life RFC=E2=80=9D for obvious enums, for some time now. Basically, = backed enums without a value receive the =E2=80=9Cobvious=E2=80=9D value. S= o a string backed enum gets the name, while an int gets the ordered number.= =C2=A0

I think something like that makes more sens= e than trying to decide what the =E2=80=9Cnatural value=E2=80=9D of a unit = enum is.=C2=A0

=E2=80=94 Rob

<= /div>
It makes sense that if a Unit Enum were to be given a `value` we = would have a hard time defining what type such value should have. This stre= ngthens my desire for Larry's suggestion for String-backed Enums defaul= ting to their names. That way, we sidestep the issue of the value type of a= Unit Enum, we avoid a potential breaking change by introducing a method th= at could conflict with userland and it also makes it opt-in. By adding `: s= tring` to a Unit Enum, we make the `->value` equivalent to the `->nam= e` and receive the from() implementation for it.

I= t's currently undeniable that a Unit Enum name is a string.
<= br>
--
M= arco Deleu
--0000000000004e26a6063981baf9--