Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112698 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82849 invoked from network); 31 Dec 2020 13:18:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Dec 2020 13:18:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BDC7F1804CF for ; Thu, 31 Dec 2020 04:53:11 -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.3 required=5.0 tests=BAYES_20,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 ; Thu, 31 Dec 2020 04:53:11 -0800 (PST) Received: by mail-wm1-f51.google.com with SMTP id c133so7265763wme.4 for ; Thu, 31 Dec 2020 04:53:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=tGzvRxOuccyJyVlfZJjp/TkLF2/nTGzTo8gEG5yf3pU=; b=HAr9QlhrasF/15aMGluxpS1qfptdkAgAXgZjEn47IsxoZe6N6wN6WJ06WaQ4iEO04A MfIcFAdrGdI4XTIU6UbCFzhzHXdVhokf8eUPe2u1oVE9Dh4/f014V9wwbYkfvZFfat+W cR0a9GyMJay4QZCtYMErKNOheguQ10+ogIIchgxAch9z6W/hWfUe94uR/vPAq8RvePRh cor4jzDIGwmc10jPeOIoW2zhd1IQl55XyIYUoPq1BVjyJEtMT6iNzRxUT4W97kjBWHKt RyI9HKYjH4uKs1JWv1o4h5EwqrINr687qBbYvrb63XW0TBSP2/YShO7RtamTlwMGXllu fh9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=tGzvRxOuccyJyVlfZJjp/TkLF2/nTGzTo8gEG5yf3pU=; b=E4ivCWZFgGbrMCTYJ1i1Pl1VnABF66w8dzFFjN6Y6mzs6u1cxSfFeu67mtA2Ubl76N qS7E6m4CsoDcAd5RQGriACST404XxhXrsZDA0fb8sRlSWwdryN9Usvnz73HP632UmoAl cuBFJzt3DHnOgw5cX8mJxVSAR3Ny1xeuFP4mJbgRyDfkb0M6vnn8X6nrHYmX7HmHyjR9 /daDFd3R4yIglC5r6YeSh9XHlMwW2MfH27IFme1XIX5xf5UL1bRFd71LRiTyYvilBc7Y E0XdGDf165bHFX2rZLxI9bPpb81glL2RAELF2Smp3gXYbdPMZOvXGOZx7hpv9S6A/WjG JoXQ== X-Gm-Message-State: AOAM530UbZG/tbYVSpUgBzsTAwM88eRX2EZYo+7NPsNIfhygvsRMoNuc 2PM7RAHNAAMgEs90ln7Olrrt68Idy3Tbcg== X-Google-Smtp-Source: ABdhPJy9Iy6DmIi3YUHrY2zrrkRiC2iP8dBeffD6aMwBbksTGzr5CBJHPAwsWtruDrvKvKiXp1JfUg== X-Received: by 2002:a05:600c:218a:: with SMTP id e10mr11677516wme.27.1609419188283; Thu, 31 Dec 2020 04:53:08 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id b200sm12895018wmb.10.2020.12.31.04.53.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 31 Dec 2020 04:53:07 -0800 (PST) To: internals@lists.php.net References: <8aa05350-05fc-df9d-e5d6-fa0f4feb57ba@alec.pl> Message-ID: <4eec7448-f7ab-9955-8c2d-68cd4f822535@gmail.com> Date: Thu, 31 Dec 2020 12:53:07 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Enumerations, Round 2 From: rowan.collins@gmail.com (Rowan Tommins) On 30/12/2020 21:24, Aleksander Machniak wrote: > My argument is that, from an end-user perspective, I don't really see > why Unit and Scalar enums have to have different "API" at this point. > I'm talking about ":string"/":int" in the enum definiton as well as > ->value and ->from(). My personal opinion is that for many enums, explicitly not having a scalar representation is a good thing. This is basically similar to my opinion of __toString() etc: if you have *multiple* ways to convert something to/from a scalar, blessing one of them as "default" is arbitrary and confusing. For example: enum BookingStatus {      case PENDING;      case CONFIRMED;      case CANCELLED;      public function getId() {            return match($this) {                 self::PENDING => 1,                 self::CONFIRMED => 2,                 self::CANCELLED => 3,            };      }      public function getCode() {            return match($this) {                 self::PENDING => 'PEN',                 self::CONFIRMED => 'CON',                 self::CANCELLED => 'CAN',            };      }      public function getEnglishDescription() {            return match($this) {                 self::PENDING => 'Pending Payment',                 self::CONFIRMED => 'Confirmed',                 self::CANCELLED => 'Cancelled',            };      } } Regards, -- Rowan Tommins [IMSoP]