Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112693 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65602 invoked from network); 31 Dec 2020 10:28:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Dec 2020 10:28:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 251321804E4 for ; Thu, 31 Dec 2020 02:03:06 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, 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-il1-f182.google.com (mail-il1-f182.google.com [209.85.166.182]) (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 02:03:05 -0800 (PST) Received: by mail-il1-f182.google.com with SMTP id n9so17046048ili.0 for ; Thu, 31 Dec 2020 02:03:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EvEIe6PlOsyTDk2g05y2q6Z/62AST4Jt/GMnZcGa9yI=; b=SFoAjle4lYUxY9gnkjk0iuGOG41EkNtJ1rE1CvP6QlwOdUTTlKV5/HBLK3ugnSSPzx uf+nHpHNqtG9Iuw1kYafi2m8OpE2VaMgo4apy2OPgAy2B5UfwEfn6AH3FqwZKs/aaTmW 9TZvMKuQJnhZWeIbDDqpo+Kr79caqE+JaTBWIlvhWsDDgVER2pzU2WKW4s/j1Du7z3+q Bx4RmTs+WRi2+/WK9rsb8J37DDCdzglPwm5Mqzs540PFE85uMzgbPM3b3wnCdYd3VRtV jpyEI/AXvL9aznU7KL4pNYtwhoKSNBwzkm+AsmZuAQ06/pwbYU4M+0ZqYcV9maNv+zk8 9cUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EvEIe6PlOsyTDk2g05y2q6Z/62AST4Jt/GMnZcGa9yI=; b=Ms8eaarBHI1h+QcLionA3TL9hQvt0V5QBoK8pMSj2vFFy/9EnPsO7aTB8m4VY+2M0o ywKe95L0EEcwbeTks5jkdQ/CqE/GHhDT2bDbLPidflfChBcwE/FqRC/eTJMp7eQFYPko aHxgff8x2zUtx3JLo0/FkMEamYA1YUYqIuTdNWwsdnfb4tsUgaZMf0Lcmbb7AxU5BmFo /e6bYVw3NDHlbnjW5ecWD8h0Im7FYll7J4s4jKrJuwozCyX10D6J3JdkbEE7vjXACGU6 +gJYO8r54OWgNIMOPSB4JHJzG4AjNmlNZwl96UhPNqoSYaKCitxcnBiC1DMtIkFpLu0T eaqg== X-Gm-Message-State: AOAM532L493GVfs//wkNeDcLUxqKfWJbHyMngSy3gfUTi9JqkGGzJxx4 o3npCcVLrQ1JWLHYHrg3Ar2RU9QisCM9IukJ/VX8TAdZhuaz/Q== X-Google-Smtp-Source: ABdhPJyXWY9M1RIGnRNjZ94bHuABJro+WclXZViG6+7ACXqE6dJQSEwzYy5q/wLecidi8s5o5wNCcesYxeGCYJuJTGg= X-Received: by 2002:a05:6e02:c6a:: with SMTP id f10mr56610111ilj.264.1609408983718; Thu, 31 Dec 2020 02:03:03 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 31 Dec 2020 11:02:52 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000c5df1a05b7bfba93" Subject: Re: [PHP-DEV] [RFC] Enumerations, Round 2 From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000c5df1a05b7bfba93 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Larry, pon., 28 gru 2020 o 21:22 Larry Garfield napisa=C5=82(a): > Hello, Internalians! > > After considerable discussion and effort, Ilija and I are ready to offer > you round 2 on enumerations. This is in the spirit of the previous > discussion, but based on that discussion a great deal has been reworked. > The main change is that Enumeration Cases are now object instances of the > Enumeration class rather than their own class. Most of the other changes > are knock-on effects of that. > > Of particular note: > > * Cases may not have methods or constants on them. They're just dumb > values. > * Enums themselves may have methods, static methods, or constants. > * Traits are supported, as long as they don't have properties. > * The value() method on scalar enums is now a property. > > The full RFC is here, and I recommend reading it again in full given how > much was updated. > > https://wiki.php.net/rfc/enumerations > > The implementation is 98% complete; there's still a few lagging bits in > reflection, and some opcache bugs that Ilija is still stomping on. > I really like the shape of the current RFC. I'd like to ask a few things: 1. Regarding the Scalar Enums since scalar values need to be literal and by design they're read only why they use a spear "->value" on enumeration? A spear "->" in objects is dedicated to class properties and by default they make thinking of property which in most cases is read-write visible. An example using Suit enumeration from RFC: // when I assign an enumeration to variable $var =3D Suit::Spades; // then reaching it's value using "->value" echo $var->value; // 'C' // Looks just like an object property fetch By default if a property is visible it is write accessible as well, which may confuse. Instead of using spear "->value" would it be possible to fetch the value just like object constants? print Suit::Clubs::value; // 'C' echo $var::value; // 'C' This mentally indicates by default that it's value is constant, simple scalar value and read only! 2. Regarding the Scalar Enums declaration syntax enum Suit: string { case Hearts =3D 'H'; } Would it make sense to move the part declaring enumeration value before enum name? I think it was put here to look similar to function return type, but IMHO it looks better and reads easier when moved before enum name: enum:string Suit { case Hearts =3D 'H'; } Leaving the space between enum name and bracket for further extensions in future. What do you think? Cheers, Micha=C5=82 Marcin Brzuchalski --000000000000c5df1a05b7bfba93--