Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115614 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 67675 invoked from network); 30 Jul 2021 19:34:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Jul 2021 19:34:14 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E767118033A for ; Fri, 30 Jul 2021 13:02:01 -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-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 13:02:01 -0700 (PDT) Received: by mail-wm1-f50.google.com with SMTP id a192-20020a1c7fc90000b0290253b32e8796so7826496wmd.0 for ; Fri, 30 Jul 2021 13:02:01 -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=OK1nAEz+GvbR8mOhfINoBp1ITANYyX5L60xu2J1Y+Sc=; b=EiZr1R4TXvhEzQaUr0WVnJexXNTvnapJWDHMdsI3sB2IiQT9M+PWpJ33PQBcjEgTg3 /ST6V6Fc22O2B4V+UVDcja+KKiTvXNslI/M+0dZU31DHGrCc7rlcaOM4UFDydD9sjrQL rbJqSG8oORSG6yN5dwuMv27ilzqfDM711+u7nqVO4HjXJJJj1wxv6f1/jIimobYIGwg9 5JN5kJj7h8bdkKQ0t66Nz82h5jsW5JH5YJh6/wSQFPRX8QbDO2cVfJylbypxsxYxVmnL nJZtITkzl1+9Dh3++C0AUFXe2bOHB80nd9HiiEXyGVmdvgGXpD3oeM9G81SaFFmP69CO TurA== 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=OK1nAEz+GvbR8mOhfINoBp1ITANYyX5L60xu2J1Y+Sc=; b=TVfqCTqxTyYRWvDuHZtEtmt2BzGW8P9kBZl8cwsV/KYhwdVhHxwVr68LKuWmzuf1iV jyclrUoDujK0dX9hhUr2PoH78o+lpwwOYY8LYpHCwxGlqy2oCuxgDE8IwAU+hsoGiTdF ZcQC7JdpigReZ5m7UGtgsFhBktlCNhdhEtFzXQJEdMPV8WrgP/GP3+hnk5U75SCxY9dS 2FUnidyH001MUqMNXNHkJDoTHFap70tdZoioULJ2KtUB5pOylGgsIqulRfHluBjOhOd+ JS51FM08Vp4NNnEzZZH+f9Yv8DUetOq18t+8rm9yIxMnyI913ckl33u0wll4Qr615A8X /Vgg== X-Gm-Message-State: AOAM533hpMIevIhiFWgX3UIdzdf3gEkNwROBUSA+hpuaKpQmrd9i5tZZ A8OqMIegFyKMx31x9iVgvwVj3YoaF6k= X-Google-Smtp-Source: ABdhPJzHNH9CWdCBdWC8xbyeZqzCDzkh9wG/4B2/RfTtXQN1zsH+o6evpcA0Tt1/gf+AJEHkOqOcvA== X-Received: by 2002:a7b:c350:: with SMTP id l16mr4853164wmj.151.1627675319671; Fri, 30 Jul 2021 13:01:59 -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 w1sm2767676wmc.19.2021.07.30.13.01.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Jul 2021 13:01:59 -0700 (PDT) To: internals@lists.php.net References: <1627603260.540422871@f450.i.mail.ru> <1627647610.417816021@f463.i.mail.ru> <1627665861.375684812@f178.i.mail.ru> Message-ID: Date: Fri, 30 Jul 2021 21:01:57 +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: <1627665861.375684812@f178.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 18:24, Kirill Nesmeyanov wrote: > enum ErrorGroup: int > { >     case NOTICE = 0; >     case WARNING = 10; >     case ERROR = 20; > } > > enum ErrorCode: int > { >     case UNKNOWN = 0; > >     case A = ErrorGroup::NOTICE + 1; >     case B = ErrorGroup::NOTICE + 2; >     case С = ErrorGroup::NOTICE + 3; >     case D = ErrorGroup::WARNING + 1; >     case E = ErrorGroup::ERROR + 1; > } As I say, those are not enums in the way the current feature defines "enum". An enum, as implemented in the current 8.1 alphas, is not just a special kind of constant, even if it has an integer or string associated. Every enum is its own type (essentially a class), and every value is a distinct value of that type (essentially an instance), which compares equal only to itself. var_dump(ErrorGroup::WARNING); // enum(ErrorGroup::WARNING); var_dump(ErrorGroup::WARNING == 10); // bool(false) var_dump(get_class(ErrorGroup::WARNING)); // string(10) "ErrorGroup" There are languages where enums are just fancy names for integers, and you can write things like "if ( ErrorCode::D >= ErrorGroup::WARNING )". In my opinion, that makes enums much less useful, because it means you can also write nonsensical things like "if ( Month::JANUARY <= Day::WEDNESDAY )". If you want to pass around an integer, but have a convenient name for it, you can still use a class constant. The main value of native enums, in my opinion, is being able to write strongly typed code saying "this accepts a value of type ErrorGroup, and nothing else". Regards, -- Rowan Tommins [IMSoP]