Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112761 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11543 invoked from network); 5 Jan 2021 13:34:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jan 2021 13:34:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 069DE1804F4 for ; Tue, 5 Jan 2021 05:11:04 -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.6 required=5.0 tests=BAYES_00,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-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (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 ; Tue, 5 Jan 2021 05:11:03 -0800 (PST) Received: by mail-wr1-f47.google.com with SMTP id d26so36070674wrb.12 for ; Tue, 05 Jan 2021 05:11:03 -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=wMzdgW+waYLmRr7UnnI1PBfHwjv18iZQF9LUlydpYVg=; b=FV3hkaI7F7NmM9Twh0ANMxAwyL4xkb0/GpSUqJ41Tgzl81/cmjZ8Qy0Thmg6LxdsIg DvDQVPspZ/3SYfG+NnoYOkmWN0puZilLAUNqLH9ZUgDHvY9Z/eqHbMqD7pvIowWd+Sw4 ZB7fnF4dMsq9gVGAC+2FtAaxmK9Lr412WRX53UqP3tHs9y68JJlJVPZ1xFJjYcAt6RlQ I4Lt6K8azvNGdI67Cwm4o5S7v6oYRSGiby+rLbwGC9dxkgRp2SuoTaOB3kWMlpTuhmzx pO3EhxxJn7dogwXzZg1U4T13a2WMLxxmaftN5loNpdGXmsXIWaIKIrhUI3PunVK1OlOZ s0Aw== 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=wMzdgW+waYLmRr7UnnI1PBfHwjv18iZQF9LUlydpYVg=; b=tsIYuP9RzGMRgZagVwhtd66gjLmpek0syDOL2KGaMn0eqNy2FJnF//yP6Avu6EMHh2 9kysDfGc6ccwjZQ/MmhV3dlCd0hrepTREzS7W9/45SauqJ3y3PxCi7A/4D8+UCEx9sp0 jLeA9OyZ+iE7fbaABMImakWzATP3uTxn8Szii0hIbRrZqv1y/tGE7fcC+KOpmfPlbxk8 ds7NoA0cuTYxjnhmRkxnZtgy5/ROx0aKq7GN9zq9KTW36f4hJdjMRVnh6SLQPF/3RtGs KbjAO/VnHsLX5L3uHlWN5n07bdhHvXjuzXx/QDPDbtL/mvVc5AM8YxgGn7N8crLhkzIt YwtA== X-Gm-Message-State: AOAM532WG/sLrcR69EeFUmvvOmZDU4/ii9GnHxDy1VRhcOh1U/l00XBS yFd6Y0kSZ+eioRf3wQhjag3QCJe9eOQwNg== X-Google-Smtp-Source: ABdhPJyTN58Z/7IvQSg4YBfag04mt0MWl2HkCPnVc4lCZGO9DfMSoZMRevmg4DSLJYrIhrEpUIL+Mw== X-Received: by 2002:a5d:4683:: with SMTP id u3mr85688305wrq.19.1609852261543; Tue, 05 Jan 2021 05:11:01 -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 g78sm4112061wme.33.2021.01.05.05.11.00 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Jan 2021 05:11:00 -0800 (PST) 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> Message-ID: <5c4ff247-4492-f9fb-cc50-1b50de4e8406@gmail.com> Date: Tue, 5 Jan 2021 13:10:58 +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 04/01/2021 22:04, Mike Schinkel wrote: > I don't quit get how you are thinking of with ": string"; can you give an example? The current RFC requires the declaration of a Scalar Enum [1] to include the scalar type, so it looks like this: enum BookingStatus: string {       case PENDING = "PENDING";       case CONFIRMED = "CONFIRMED";       case CANCELLED = "CANCELLED"; } The simplest opt-in for default scalar values would be to declare the type but no values, so the above could be abbreviated this way: enum BookingStatus: string {       case PENDING;       case CONFIRMED;       case CANCELLED; } However, it's probably better to be a bit more explicit, e.g.: enum BookingStatus: auto string {       case PENDING;       case CONFIRMED;       case CANCELLED; } Either way, we'd have to decide if it was allowed to specify some values but not all, e.g.: enum BookingStatus: auto string {       case PENDING;       case CONFIRMED;       case CANCELLED = 'TERMINATED'; } A more verbose but possibly clearer syntax would be a token on the case statements themselves, such as "= auto", to mean "set the value for this case based on its constant name": enum BookingStatus: string {       case PENDING = auto;       case CONFIRMED = auto;       case CANCELLED = 'TERMINATED'; } There's also the question of whether an automatic value for ints should also be allowed, e.g. incrementing in declaration order. This is more dangerous, as adding, removing, or re-arranging cases can affect the values of *all* the cases in the enum, but is done in some other languages. [1] https://wiki.php.net/rfc/enumerations#scalar_enums Regards, -- Rowan Tommins [IMSoP]