Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112423 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81537 invoked from network); 5 Dec 2020 13:11:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Dec 2020 13:11:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 509D31804C3 for ; Sat, 5 Dec 2020 04:39:31 -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_50,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (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 04:39:30 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 2E80D5101324 for ; Sat, 5 Dec 2020 12:39:29 +0000 (UTC) To: internals@lists.php.net References: <6cdd2d8c-39ea-c3a3-5f42-e355dc601539@processus.org> <12c0779e-8c90-b80a-998e-9808a3314146@fischer.name> Message-ID: <73cc4bc3-c13d-9fb2-e72d-4be3889f122d@processus.org> Date: Sat, 5 Dec 2020 13:39:28 +0100 MIME-Version: 1.0 In-Reply-To: <12c0779e-8c90-b80a-998e-9808a3314146@fischer.name> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] [RFC] Enumerations From: pierre-php@processus.org ("Pierre R.") Le 05/12/2020 à 12:14, Markus Fischer a écrit : > Hi, > > On 05.12.20 10:22, Pierre R. wrote: >> I think that ::cases() should always return an array/iterable without >> keys, and let userland write their own code to create hashmaps with >> those when they need it. I think that having one case (non primitive >> cases) that doesn't yield string keys and the other (primitive cases) >> which holds string keys may create a confusion because behavior is >> different. >> >> If behavior is different, this would mean you couldn't mix primitive >> and non primitive cases on the same enum, which, why not couldn't we >> do that? > > I've no strong feelings and I think your idea makes sense. > > But I would argue, of course without having hard facts, that the > _majority_ will have the use-case for a 1:1, aka array with key => > value, mapping. > > Thus I would argue that having (considering your proposal being added) > still such functionality would be useful for a very wide-audience > without everyone having to reinvent a helper method to use the iterable. > I agree with that last statement about wide-audience usefulness, nevertheless my opinion is that it's not about being useful to the most but bring consistency at the language level. If for consistency I have to write an array_map() call whenever I need a choices list, I'm good with that. Moreover, bringing enum is a thousands times more useful than having a sugar candy method for building hashmaps ! There are many use cases you'd want an hashmap out of those enums, but each use case will probably differ in subtle ways. I'd more comfortable with a coherent behavior that everyone will understand easily, with no behavior subtleties, and each user implement its need on this side. Why not, in that case, just add another method than ::cases(), such as, I don't know, ::to[Hash]Map() for example ? Regards, Pierre