Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115621 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15404 invoked from network); 1 Aug 2021 18:29:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Aug 2021 18:29:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A23081804B3 for ; Sun, 1 Aug 2021 11:58:11 -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=-0.7 required=5.0 tests=BAYES_00,BODY_8BITS, 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-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 ; Sun, 1 Aug 2021 11:58:11 -0700 (PDT) Received: by mail-wm1-f49.google.com with SMTP id k4so9104778wms.3 for ; Sun, 01 Aug 2021 11:58:11 -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=s40PDq4RHwB+iCRAIFhQ/Q5DBMxlfMscinoATcpYdEA=; b=lCAyNjnk4LngxS/rIMBMHSnLeZeydI1OhQ5ETquw4kzVom9Jvk+iY3xwhpSOWh1c8r bP9QHPkVoGUSs64YFk2z1+GkDEHYKVWBsUm8GE7S32YZu6SE+orDMTHM9F5W37ZghkqQ Kf+8JXFCc345R4HXDay3OYU/BNa5yNKjSXR2DT8IU3HcsTzMuNKncEQyEx4xB7+F0IdP 6OokxJCScDKpL/1RyU9H6Vc1uocqJC9NIIoGbNqRZl2j1F/gcsaYuGmF10Ojgukwl2pl UbSg0bEWjFkA6KsczDVqXYD5Ca76KIwL62wiuFJZ0zx8PMPnvnazNd10HBB/d01y4/IB s0UA== 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=s40PDq4RHwB+iCRAIFhQ/Q5DBMxlfMscinoATcpYdEA=; b=bU7jywlkTaAfPJcS6xXzG0C+XbTD5kpvYdDPwiflpDSbPUvupbvvy2RR/OO5RDIbzW zs4JRXYEZvgctAhQ5DebvNThFDkTyJ+gAkQglPmEAaTKHRaCYH8/xabOlIx3dxzS3wZ2 CPDZyK8ERoOAWyTo3bCsd1PfJtJ2O9mhEEvx6CgEXkenVd2WaMCVF/Wso5S5wdbJE0uA atYx0AHnUZE4H1AuEFRKd1fWUlbaVBAAerrM8+siNDC+QMbtIz5TgLHtnZ3zM+xFlIw4 COglNz3KpFxv7XzJmLhCx7fIvkZ1YwBLriCZ3iDFcWbyl+sDa6AEFUSfFpX77tamT+Sp RNDQ== X-Gm-Message-State: AOAM531DoGGz4dhHpsiHgSjqVO9osod0FUKfsWy6icxs/7yGtZ7PDBr0 6ChNp8aDmNGirhhFghFRqztNxRgueuQ= X-Google-Smtp-Source: ABdhPJwBsWYbG5YlQ/dEiWZTnztTekeWka+rqDYhrRcjkUjFIDPhju+tWOBZHtBIcNHIAbVCzuiWkQ== X-Received: by 2002:a1c:a94f:: with SMTP id s76mr12739310wme.17.1627844288362; Sun, 01 Aug 2021 11:58:08 -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 h16sm8678085wre.52.2021.08.01.11.58.07 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 01 Aug 2021 11:58:07 -0700 (PDT) To: internals@lists.php.net References: <22EF92EC-C5A3-498E-9EFD-DE2B5B204BB7@gmail.com> <6e668a49-d69c-7b6d-f9c4-1d3fe2058d27@gmail.com> <7FAE3AE2-F8C1-4774-9B84-721DE8FF49D4@gmail.com> Message-ID: Date: Sun, 1 Aug 2021 19:58:06 +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: <7FAE3AE2-F8C1-4774-9B84-721DE8FF49D4@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] RFC: autoconst From: rowan.collins@gmail.com (Rowan Tommins) On 01/08/2021 16:59, Serhii Smirnov wrote: > class Features > { >     const FEATURE_FLAG_WITH_SOME_LONG_NAME = > 'feature_flag_with_some_long_name'; >     const FEATURE_SOME_ANOTHER_COOL_FEATURE = > 'feature_some_another_cool_feature'; > } That looks like it falls into my first category: the actual value of the constant doesn't matter, you just need to be able to compare against it later. That makes it a perfect use case for PHP 8.1's new "enum" type, where you'll be able to declare this: enum Feature {      case FEATURE_FLAG_WITH_SOME_LONG_NAME;      case FEATURE_SOME_ANOTHER_COOL_FEATURE; } You can then even define the "isEnabled" function so that it only accepts Feature values, not strings (i.e. "public function isEnabled(Feature $feature): bool { ... }" instead of "public function isEnabled(string $feature): bool { ... }"). If you're not familiar with the new enums, the best documentation at the moment is probably the RFC which proposed them: https://wiki.php.net/rfc/enumerations I'm really looking forward to using them :) Regards, -- Rowan Tommins [IMSoP]