Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112701 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6397 invoked from network); 31 Dec 2020 18:39:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Dec 2020 18:39:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 886001804F3 for ; Thu, 31 Dec 2020 10:14:20 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 31 Dec 2020 10:14:19 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id A234A177D for ; Thu, 31 Dec 2020 13:14:18 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Thu, 31 Dec 2020 13:14:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=9xo/PlrtKM4N1jocY15U2ep4EbstUUulRLwpHeV8w nE=; b=OLvwdxDFDoeZ5SSgCuCRKsltattmf1UETG/5DOGTb8xFng6r3QV8ZJ01e xgciqPIbM9P/POFYd5UoxcLekSzL5qx97rFs7W+i0QtKRHoeOKH0sA4VxRnJvmFU 6TPJiydRSPW/Ld8saI+MXfOLhB1gmHjvN/ixxkXTuIISGNQZUNMjkdpInq6CEHkp 8JQfERBagRQ18xvdRWHcqjE3fPuzm8wCm41qLKKYovjdamSRK19abbxI/+q6RAG0 WwiLDiYmqz43UE3rSY5CTvv9EgSsx77/+QfUhnSwSQLG8ZMopjCA/ZX0aYFQE1R5 9Exl0DdjhnS5Fbwc8sK5d+j/KIZCg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddvhedguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeff jeelfeejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id C6F7414200A2; Thu, 31 Dec 2020 13:14:17 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Thu, 31 Dec 2020 12:13:57 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Enumerations, Round 2 From: larry@garfieldtech.com ("Larry Garfield") On Thu, Dec 31, 2020, at 4:02 AM, Micha=C5=82 Marcin Brzuchalski wrote: > Hi Larry, > I really like the shape of the current RFC. >=20 > I'd like to ask a few things: >=20 > 1. Regarding the Scalar Enums since scalar values need to be literal a= nd > by design they're read only why they use a spear "->value" on enumerat= ion? > A spear "->" in objects is dedicated to class properties and by defaul= t > they make thinking of property which > in most cases is read-write visible. >=20 > 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 >=20 > By default if a property is visible it is write accessible as well, wh= ich > may confuse. >=20 > Instead of using spear "->value" would it be possible to fetch the val= ue > just like object constants? >=20 > print Suit::Clubs::value; // 'C' > echo $var::value; // 'C' >=20 > This mentally indicates by default that it's value is constant, simple= > scalar value and read only! We originally used a method in the first draft. We changed it to a prop= erty for three reasons. 1) There's lots of talk lately about immutable properties, so one way or= another "it's a property so I can write to it" is an assumption that wo= n't hold much longer. 2) The property has to exist internally anyway, because under the hood i= t's just a class with a property, so the name would still be reserved ei= ther way. 3) Given 1 and 2, adding a method on top just adds some micro overhead f= or the method call. A constant-esque syntax wouldn't be possible because under the hood, the= cases are objects now, not classes. We could put constants on Suit, bu= t Suit::Clubs is an object, and objects can't have constants independent= of their class. > 2. Regarding the Scalar Enums declaration syntax >=20 > enum Suit: string { > case Hearts =3D 'H'; > } >=20 > Would it make sense to move the part declaring enumeration value befor= e > enum name? > I think it was put here to look similar to function return type, but I= MHO > it looks better and reads easier > when moved before enum name: >=20 > enum:string Suit { > case Hearts =3D 'H'; > } >=20 > Leaving the space between enum name and bracket for further extensions= in > future. > What do you think? That would be a very one-off syntax. The colon-suffix is already establ= ished in PHP, and i the same as the syntax used in Swift. What you're d= escribing looks a lot more like a generic. Which... I suppose in some w= ays this is if you squint really hard? I don't have much of an argument= against it other than aesthetic. I have no idea what the parser would = do with it. --Larry Garfield