Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120117 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86161 invoked from network); 24 Apr 2023 02:33:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Apr 2023 02:33:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 08FAD180382 for ; Sun, 23 Apr 2023 19:33:03 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-vk1-f171.google.com (mail-vk1-f171.google.com [209.85.221.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 23 Apr 2023 19:33:02 -0700 (PDT) Received: by mail-vk1-f171.google.com with SMTP id 71dfb90a1353d-4436189d2a9so1559025e0c.1 for ; Sun, 23 Apr 2023 19:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suiteux-com.20221208.gappssmtp.com; s=20221208; t=1682303581; x=1684895581; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5FWvzJWUPX2iOPyDFpw+l4IKfae07OjOtD7zhhJj2BM=; b=Ejsj6CtGTSwWteetOYnvRdjWQ1N6lU45Hvj1SN9h6ArJpHGUoO517EaBdRrIAnsHOL 9UlzW2JEh7DyBqut+xGQgOFKFBQO7xvz6IG3CcJvF0beFHL/BAOzQbpdHoZH5vShw6W+ gvzr6Yi8n2o2BFrdEpRgqAfpMmfNy2VRAVDo0Y1gaDjTmh/7HCZ/bDJwo1rznO4oocOw UmpU2GPqDfAH38FuU+RNBvhg+ry+310l1scES07e841vuNSrJCAGp3Mq32/n+FbaGl8A /cCuAwBznrz24TMNU/D4s0y99dTEcGXsREi9AFCIiDewFeFQI3n43ngRhhhyP6mVuOvQ sVCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682303581; x=1684895581; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5FWvzJWUPX2iOPyDFpw+l4IKfae07OjOtD7zhhJj2BM=; b=F34wxJgl498EqmvGgEz5yb9DutCQMlx4xlzBZ9JwfmYy0WTRjvINbqZTFRiDR9uq+B Azn2gMhd+oriaX1B4ibbi4znK+2NyKT7lOZNG6V2pA597OSUf6mv5fwy5UTBaV7bwA8Y c/9iAIiAjeD/3ns4HVdYRdottqQ9333+6nYpmxbtz4kh3JcStGueQnK6dEFqbx8Z0ZWZ vUIat7pRYoDj/mTAPLA31kD77M9fC7AUvHLX8bXQUboLAE+aljlxGQRyuoQN2M4XfbFJ pCeB61tpjSVvtsX0qZw+bwEJh2+DRHg3uBwogqC2VCS4dVbogiPV6WnzQtWkz/y/pAi9 BQ+w== X-Gm-Message-State: AAQBX9fMedhxoqwxT8jfDC/sJWYb6ToDYCf0JMcsRLl9o+EZSliR4MLF wZLymI7P7myoHY3T4XexUm8AxQkxq4tDuRlWqjxI2w== X-Google-Smtp-Source: AKy350bP7SDvZYz2jWcghrf0cdyAcAd2uAzZWGn/flDDjCZJOqJzTi9kLmXYHhxzXnxwcnM6ESq2rmI/LYaEdkOTBug= X-Received: by 2002:a1f:e047:0:b0:440:8a24:e716 with SMTP id x68-20020a1fe047000000b004408a24e716mr2729660vkg.6.1682303581453; Sun, 23 Apr 2023 19:33:01 -0700 (PDT) MIME-Version: 1.0 References: <3e131a9b-9f5e-5eb0-33e4-a3a03327e157@gmail.com> In-Reply-To: <3e131a9b-9f5e-5eb0-33e4-a3a03327e157@gmail.com> Date: Sun, 23 Apr 2023 21:32:49 -0500 Message-ID: To: Rowan Tommins Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000006093e705fa0bd30b" Subject: Re: [PHP-DEV] Introduction - SuitespaceRnD From: garet@suiteux.com (Garet Claborn) --0000000000006093e705fa0bd30b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for all the tips and feedback so far. I will try to respond to clarify each so far. > On Sun, Apr 23, 2023 at 12:53=E2=80=AFPM Rowan Tommins wrote: > - If the aim is to allow array keys to be enum cases themselves (or > objects in general), you'll likely need at least a partial > implementation before taking it to a vote, as the impact on the rest of > the engine, in terms of performance and complexity, will be a major > deciding factor. You can still draft the RFC beforehand to judge the > interest, however. > > - If the aim is to automatically cast the enum cases to ordinary string= s > or ints, expect some scepticism. I for one believe that it is an > essential property of enums that Day::Monday =3D=3D Month::January shou= ld be > false, and it follows that array_key_exists(Day::Monday, [Month::Januar= y > =3D> true]) should be false as well. First, we are indeed placing resources on getting this implementation on our end (though any guidance is more than welcome as this is my first attempt with the internals) Niels Dossche also mentions we should request RFC karma. I was unclear if I should wait until we have implemented further before posting, however a simple text version exists already. Happy to do so now. To your main point; I do agree with the general thrust of feedback on the enum implementation given in that issue thread, which aligns more closely to your second case. While the direction I presented in that issue regarding the meaning and purpose of enumerations in programming and more broadly did overwhelmingly outweigh dissent, there has been considerable pushback about typing so far. However I would suggest that this can be roadmapped into a win-win scenario rather than an A vs B scenario and the RFC tries to reflect this. Whereas object keys are a whole other can of worms at the moment, the RFC makes recommendations which would align with both of these cases. For as long as object keys do not exist, the value semantic would apply. Once object keys do exist the only difference between the typesafe goal you are looking for and our recommended implementation would be that *Day::Monday =3D=3D Month::January *would be true *but* *Day::Monday =3D=3D=3D Month::January *would be false Similarly with ArrayAccess, if we ever get more type resolution in the context of keys this can be conveyed simply by strongly typing the function parameters rather than current string or int types. As soon as PHP keys accept object types, or even just a third enum type, this would immediately enable the desirable *$current_month =3D $month[Day::Monday]; // Error* Assuming you indeed typed your getting such as *offsetGet(Month $offset)* *Lynn *mentioned, " I am also interested to see where this goes, especially beyond the scope of just enums." This relates to the further roadmap concept I am referencing -- which is not fully detailed but noted in the initial RFC, and the RFC is designed as a useful milestone towards that roadmap. We and many other PHP < 8 projects have usage patterns already established with class constants which should rightly be seen as "hold ups" in promoting the use of enums over the old way. By incentivizing such code to make the switch to enums and providing a behavior which has no side effects on existing code, other than removing an error, this is a benefit. Finally because I am familiar with the case of labeling indices especially, I am aware of methods that will help bridge the gap to eventual object keys. Though out of scope for this first iteration that is a large part of the purpose. If implemented, a follow-up RFC can go into more detail; but the gist is: existing object key RFCs have discovered ways to implement this for select types of objects but not the general case. With value semantics implemented, and some glue code in userland, we have recovered the ability to overload array mechanics further already to allow type checks. If this use pattern were further enabled - even the simple value semantics, we can then use enums as aliases to type checking mechanics for object keys purely in user land. From there it becomes a simple matter of closing the gap until at least enums can be a third type of key which provides a type safety proxy to related objects. This in turn could be further contracted if full object keys become available - which is enabled by the use patterns preexisting in userland. ---- Though I am working along this line of reasoning above to edit the need for that debate out of the roadmap, I will reiterate my original reasoning for favoring the second case, prioritizing value semantics. First because we don't really have an option as long as key contexts such as ArrayAccess only support int and string at present. More strongly: Enumerations are constructs which span many disciplines for which strong assertions can be made about their correlation to lists and coverage of such lists. Even in cases where an enumeration's order does not have a numeric definition, the ordinality still exists and may be exploited in many ways. Enumeration as a word itself implies "to number" or count, and as such has well-defined mathematical properties which relate to natural numbers. There are categories of algorithms which rely on this and cannot be implemented by reflection or other means. Specifically, many constant time algorithms can take advantage of labeled indices and some cannot be implemented without them. All that said, after the various feedback so far the history I cared about turns out to matter less than the simple fact that instances of an enum are effectively userland symbols. Example / TL:DR: I may presently write $selected =3D $list[ $x ]; Whether $x=3D0 or $x=3D'apple', I am not required to use $list[ $x->value ] Symbols map to their value without requiring ->value, but retain typesafety in many contexts. Ultimately we do want to get there but start at values. Thanks again for all the feedback, Garet Claborn ------- Also, Robert Landers in response to your userland code. There are cases where it is possible to get very close semantics On Sun, Apr 23, 2023 at 12:53=E2=80=AFPM Rowan Tommins wrote: > On 19/04/2023 16:11, Garet Claborn wrote: > > Specifically I finally registered > > as I have written up an RFC in response to this issue thread > > on GitHub. > > > Welcome, and in case you haven't found it already, here's the guide to > the RFC process: https://wiki.php.net/rfc/howto > > I'll wait with interest to see the RFC, but would note two things: > > - If the aim is to allow array keys to be enum cases themselves (or > objects in general), you'll likely need at least a partial > implementation before taking it to a vote, as the impact on the rest of > the engine, in terms of performance and complexity, will be a major > deciding factor. You can still draft the RFC beforehand to judge the > interest, however. > > - If the aim is to automatically cast the enum cases to ordinary strings > or ints, expect some scepticism. I for one believe that it is an > essential property of enums that Day::Monday =3D=3D Month::January should= be > false, and it follows that array_key_exists(Day::Monday, [Month::January > =3D> true]) should be false as well. > > > On 23/04/2023 17:01, Robert Landers wrote: > > Even if it > > has to be something 'ugly' to keep people from using that itself as a > > value (similar to how js symbol types work -- a one-way cast). > > > As far as I understand, Symbols in JS are entirely their own type, and > the definition of objects directly allows property keys to be either a > String or a Symbol; so it is equivalent to PHP allowing enum cases, but > not other objects, to be array keys. > > > Properties are identified using key values. A property key value is > either an ECMAScript String value or a Symbol value. All String and > Symbol values, including the empty String, are valid as property keys. > > > https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#s= ec-object-type > > > Regards, > > -- > Rowan Tommins > [IMSoP] > --0000000000006093e705fa0bd30b--