Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115612 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44786 invoked from network); 30 Jul 2021 13:17:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Jul 2021 13:17:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6128518033A for ; Fri, 30 Jul 2021 06:45:38 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 ; Fri, 30 Jul 2021 06:45:37 -0700 (PDT) Received: by mail-wm1-f45.google.com with SMTP id k4so6020258wms.3 for ; Fri, 30 Jul 2021 06:45:37 -0700 (PDT) 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=vTy03ijjBNisQWXczcaTxNKMM5aPTfmdQ1EGWgja5ZE=; b=TMQw+Beiy7aNk0r3/nKSHRxOb3+HbcNi5TFs6saDIOylw8du57fd6c4Da+NWoiq1KI Hm/Hee3+Ly4QiVWq1KuQ/53AU0Ur0UV4WPhvdgai/54srG5G0aYMA2EzhJGWh37UQ9jS EO2SRWC7b9HO+k9IckMy2OAZG0bxhjgg7KD57bj9ubdfjeBbtk6uLI3TbkEeGzcH/sTJ aqj7+/f6+8tyjKZ8yz5y9X/ROBfZgCCpLKkp/4q3hdFiJ7L40l+J+V8Cne4814ils91X Qg/6Mluvy5wWwtRssTZPDUgntPDRs1cuHu3KSyih60QeUqNWMM0RqznB84TwGCQe8jKT beKQ== 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=vTy03ijjBNisQWXczcaTxNKMM5aPTfmdQ1EGWgja5ZE=; b=DSxLtw0q4683r0/9MgWX5e6kamuTjcZnw/pTXFs2Vofq7eWaKqsVcX3SzVWZagiWsN QZ/Xf76ZmJW4Y9SRBqz4m/z27BLc5G/eTHmpdd9+KZZE4zPcMP+yI8hcejAbCVnMD/kO L7Tt24/rMn7YXJMmATfSDYbsl3dqMBc8qzCoJ3io9jY9kX4MU4ZpnjaZYqSFMDNZpMM9 njqVwue7NTTq3109knXIhimixDusL9sW3q3c/ppPth0hQa5N6OIOt8J1U6vhsp4/mVWR AjFdjrzdQyB8slrdMi48A0JeQiorIlcPQj37he00wcJfm0QXM9NVwz4PG+LaytmAhC+/ iYhg== X-Gm-Message-State: AOAM533lixedV5muTUg8XQK4pA9mJED9ukhdh7VYepQ4JftLestxypfX IHSx+BMsSmiJebpoT13ZIQmFq2ItzFM= X-Google-Smtp-Source: ABdhPJwQpWfF7HpUB3CW6PYcFG7WYMnSZJk188uzchytjgdmqqNYC1e66cPwy5Mfdt2azBE7oTrIJA== X-Received: by 2002:a7b:c14a:: with SMTP id z10mr3287459wmi.36.1627652735983; Fri, 30 Jul 2021 06:45:35 -0700 (PDT) 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 q17sm1840386wre.3.2021.07.30.06.45.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Jul 2021 06:45:35 -0700 (PDT) To: internals@lists.php.net References: <1627603260.540422871@f450.i.mail.ru> <306bf129-c00f-5f3e-b2de-e80afdf85d72@mabe.berlin> <1627647610.417816021@f463.i.mail.ru> Message-ID: Date: Fri, 30 Jul 2021 14:45:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <1627647610.417816021@f463.i.mail.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: Fwd: Re[2]: [PHP-DEV] PHP 8.1 enum const expressions problem From: rowan.collins@gmail.com (Rowan Tommins) On 30/07/2021 13:20, Kirill Nesmeyanov wrote: > But in addition to bit-masks, there are also at least cases of addition and subtraction (the most popular). Can't we adapt all math expressions existing in nature to specific cases, thereby building our own pseudo-AST? > > (Some::A + Some::B) * Some::C | Some::D; If you are performing arithmetic on a value, that value is not of an enum type, or at least not in the way the current feature defines "enum". If you write an enum for days of the week, you might give them integer values, such that "Day::MONDAY->value === 1" and "Day::SUNDAY->value === 7". However, expressions such as "Day::SATURDAY + Day::SUNDAY"  and "Day::MONDAY * Day::TUESDAY" are clearly meaningless. At a stretch, a language with operator overloading might define "Day::MONDAY + 1" to return "Day::TUESDAY", and "Day::MONDAY + 10" to either error or wrap around to "Day::THURSDAY"; but PHP has covered that use case by allowing methods, e.g. "Day::MONDAY->advanceBy(10)", which is more flexible and arguably more expressive. On the other hand, the expression "$weekend = Day::SATURDAY | Day::SUNDAY" seems reasonable; but we don't need the result to be an integer - it would have no meaning on its own - we just need to be able to ask things like "is $today in $weekend?" Returning some kind of EnumSet object means we retain the type information, and can keep our values of 1 to 7 (or have no values at all) rather than having to use powers of 2. Regards, -- Rowan Tommins [IMSoP]