Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112750 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6559 invoked from network); 4 Jan 2021 15:45:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Jan 2021 15:45:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BA7E71804F6 for ; Mon, 4 Jan 2021 07:21:45 -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=-0.1 required=5.0 tests=BAYES_05,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 ; Mon, 4 Jan 2021 07:21:45 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 089515101324 for ; Mon, 4 Jan 2021 15:21:42 +0000 (UTC) To: internals@lists.php.net References: <8aa05350-05fc-df9d-e5d6-fa0f4feb57ba@alec.pl> <4eec7448-f7ab-9955-8c2d-68cd4f822535@gmail.com> <7d8ce2a2-8d85-4312-af22-da643faa3a7f@www.fastmail.com> <1BC8BF20-B961-4360-855B-5BB95338BB8A@newclarity.net> <30e219c4-bfcb-026f-630e-bda8f21b3787@fischer.name> Message-ID: <642fa510-3dd2-da98-e0cd-3aa83ee2dd90@processus.org> Date: Mon, 4 Jan 2021 16:21:42 +0100 MIME-Version: 1.0 In-Reply-To: <30e219c4-bfcb-026f-630e-bda8f21b3787@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, Round 2 From: pierre-php@processus.org ("Pierre R.") Le 04/01/2021 à 16:12, Markus Fischer a écrit : > > I can't say whether just `: string` is too much, but in general I like > it. > > I can follow the reasoning having no value by default and opt this in. > The opt-in you suggested is very low-overhead (albeit a bit subtle, > but maybe someone has a smarter idea :) > > Maybe not evident, I like the enum RFC but think the most value for > many use cases will having automatically values. > > thanks! > - Markus > Hello, I do not agree with having values per default, this is error prone in most of my use cases. In most case where I need enums, I often need to replicate those in database too, or in message broker serialized messages: in this context, whenever I need to fix a typo in a enum case name, for example, if I use default values, I would have errors with my existing database records or live messages. I prefer to keep an explicit switch/match to hydrate values from database or elsewhere, and use a value-less enum on the PHP side. Case names are the only semantically important value for the developer, and your code should not care about having a string value. In most cases only exchanges with the outside world in an heterogeneous environment (having a database makes it heterogeneous) care about having string values. In this case, I highly prefer having explicitely written (de)hydration code than automatic magic values happening over the place. Cheers, Pierre