Am 05.12.20, 00:25 schrieb "Larry Garfield" <la...@garfieldtech.com>:

    Greetings, denizens of Internals!

    Ilija Tovilo and I have been working for the last few months on adding 
support for enumerations and algebraic data types to PHP.  This is a not-small 
task, so we've broken it up into several stages.  The first stage, unit 
enumerations, are just about ready for public review and discussion.

    The overarching plan (for context, NOT the thing to comment on right now) 
is here: https://wiki.php.net/rfc/adts

    The first step, for unit enumerations, is here:

    https://wiki.php.net/rfc/enumerations

    There's still a few bits we're sorting out and the implementation is mostly 
done, but not 100% complete.  Still, it's far enough along to start a 
discussion on and get broader feedback on the outstanding nits.

    I should note that while the design has been collaborative, credit for the 
implementation goes entirely to Ilija.  Blame for any typos in the RFC itself 
go entirely to me.

    *dons flame-retardant suit*

Hi Larry,

thanks for your great initiative and hard work in this!
I'm the author of an emulated enumeration lib [1] and really looking forward 
seeing native enumeration support in PHP.

Here are some questions about your RFC:

* How can you access a defined case value? 
  Something like `Suit::Spades->value()`

* Are the cases case-insensitive or case-sensitive?
  `Suit::Spades` vs. `Suit::SPADES`

* Are cases serializable?
  `Suit::Spades === unserialize(serialize(Suit::Spades)) // true`

* Do cases have a stable ordinal number / position and is that accessible?
  This would be very interesting on implementing an optimized EnumSet using 
bit-array / bit-set internally

* I often use metadata in enumerations and so I would be very interested to 
allow constants.
  I do understand that they share the same naming table and these needs to be 
unique but disabling constants altogether would limit the use-cases in my 
opinion.

* Is it possible to detect / type-hint if something is any enum?
  ` Suit::Spades instanceof Enum`

  This basically means that all enumerations would to based on a general enum.
  This would be very helpful on providing functionalities especially for 
enumerations thinking about a doctrine enumeration type or again an EnumSet / 
EnumMap.

Thanks Marc

[1] https://github.com/marc-mabe/php-enum

    -- 
      Larry Garfield
      la...@garfieldtech.com

    -- 
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: https://www.php.net/unsub.php

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to