On 19/04/2023 16:11, Garet Claborn wrote:
Specifically I finally registered
as I have written up an RFC in response to this issue thread
<https://github.com/php/php-src/issues/9208> on GitHub.
Welcome, and in case you haven't found it already, here's the guide to
the RFC process: https://wiki.php.net/rfc/howto
I'll wait with interest to see the RFC, but would note two things:
- If the aim is to allow array keys to be enum cases themselves (or
objects in general), you'll likely need at least a partial
implementation before taking it to a vote, as the impact on the rest of
the engine, in terms of performance and complexity, will be a major
deciding factor. You can still draft the RFC beforehand to judge the
interest, however.
- If the aim is to automatically cast the enum cases to ordinary strings
or ints, expect some scepticism. I for one believe that it is an
essential property of enums that Day::Monday == Month::January should be
false, and it follows that array_key_exists(Day::Monday, [Month::January
=> true]) should be false as well.
On 23/04/2023 17:01, Robert Landers wrote:
Even if it
has to be something 'ugly' to keep people from using that itself as a
value (similar to how js symbol types work -- a one-way cast).
As far as I understand, Symbols in JS are entirely their own type, and
the definition of objects directly allows property keys to be either a
String or a Symbol; so it is equivalent to PHP allowing enum cases, but
not other objects, to be array keys.
> Properties are identified using key values. A property key value is
either an ECMAScript String value or a Symbol value. All String and
Symbol values, including the empty String, are valid as property keys.
https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-object-type
Regards,
--
Rowan Tommins
[IMSoP]