Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112424 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90110 invoked from network); 5 Dec 2020 14:53:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Dec 2020 14:53:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C1EDB1804DB for ; Sat, 5 Dec 2020 06:21:24 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_05,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wp160.webpack.hosteurope.de (wp160.webpack.hosteurope.de [80.237.132.167]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 5 Dec 2020 06:21:23 -0800 (PST) Received: from ip5f5bd23e.dynamic.kabel-deutschland.de ([95.91.210.62] helo=[192.168.178.29]); authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1klYR6-0006B2-U3; Sat, 05 Dec 2020 15:21:21 +0100 User-Agent: Microsoft-MacOutlook/16.43.20110804 Date: Sat, 05 Dec 2020 15:21:19 +0100 To: Larry Garfield , php internals Message-ID: Thread-Topic: [PHP-DEV] [RFC] Enumerations References: In-Reply-To: Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: 7bit X-bounce-key: webpack.hosteurope.de;marc@mabe.berlin;1607178084;b85707c3; X-HE-SMSGID: 1klYR6-0006B2-U3 Subject: Re: [PHP-DEV] [RFC] Enumerations From: marc@mabe.berlin (Marc Bennewitz) Am 05.12.20, 00:25 schrieb "Larry Garfield" : 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 larry@garfieldtech.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php