Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums

2025-07-10 Thread Rowan Tommins [IMSoP]
On 10 July 2025 01:52:17 BST, Deleu wrote: >On Wed, Jul 9, 2025 at 7:23 PM Rowan Tommins [IMSoP] >wrote: > >> On 09/07/2025 17:39, Deleu wrote: >> > It's currently undeniable that a Unit Enum name is a string. >> >> If you want to associate a single string value with each enum case, use >> a stri

Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums

2025-07-09 Thread Deleu
On Wed, Jul 9, 2025 at 7:23 PM Rowan Tommins [IMSoP] wrote: > On 09/07/2025 17:39, Deleu wrote: > > It's currently undeniable that a Unit Enum name is a string. > > If you want to associate a single string value with each enum case, use > a string-backed enum, and propose some short-hand syntax.

Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums

2025-07-09 Thread Rowan Tommins [IMSoP]
On 09/07/2025 17:39, Deleu wrote: It's currently undeniable that a Unit Enum name is a string. So is a class name, as accessed by $foo::class. $foo->name on an enum case is really just the same kind of pseudo-reflection, in my view: it's telling you information about the source code, useful

Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums

2025-07-09 Thread Rowan Tommins [IMSoP]
On 9 July 2025 17:12:52 BST, Rob Landers wrote: > I’ve been thinking of a “quality-of-life RFC” for obvious enums, for some > time now. Basically, backed enums without a value receive the “obvious” > value. So a string backed enum gets the name, while an int gets the ordered > number. I agre

Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums

2025-07-09 Thread Deleu
On Wed, Jul 9, 2025 at 1:17 PM Rob Landers wrote: > > Hey Marco, > > I think this relies on whether the “natural value” of a unit enum is a > string or not. It might be, or it might not be. I don’t think you have a > compelling argument on why it is a string and that string is the name. > Persona

Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums

2025-07-09 Thread Rob Landers
On Wed, Jul 9, 2025, at 15:29, Deleu wrote: > Hi people! > > Today I tried to do `ResourceType::from()` and was surprised that my IDE > immediately screamed at me. After further investigation, I realized that > Basic Enums (this is what the RFC called it [1]) does not have these > commodities

Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums

2025-07-09 Thread Lynn
On Wed, Jul 9, 2025 at 3:33 PM Deleu wrote: > Hi people! > > Today I tried to do `ResourceType::from()` and was surprised that my IDE > immediately screamed at me. After further investigation, I realized that > Basic Enums (this is what the RFC called it [1]) does not have these > commodities bac

Re: [PHP-DEV] ::from() and tryFrom() on Basic Enums

2025-07-09 Thread Bruce Weirdan
You probably know it, but I wanted to note that you can implement it in userland with minimal effort: https://3v4l.org/DoXJo#v8.4.10 -- Best regards, Bruce Weirdan mailto: weir...@gmail.com