Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118995 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 76779 invoked from network); 13 Nov 2022 21:24:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Nov 2022 21:24:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B56AB180044 for ; Sun, 13 Nov 2022 13:24:50 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS29838 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (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, 13 Nov 2022 13:24:50 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 628293200893 for ; Sun, 13 Nov 2022 16:24:48 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Sun, 13 Nov 2022 16:24:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1668374687; x= 1668461087; bh=rXPB6oe0xmPnWfhY9SUJZ9+wDPQUSDvtubRg8ZvXi6c=; b=I 57ha4U8zC3O0RHWj+buCgSJ+AKeOaosLGn+uolyLKmqqxeuxv/Z/TfBE4OjU3+OY GS/oiere3nnSXw5Z2fquxkByWrf4eLcano5Cc5zKZcERZZ0pif54rib9UXd7Esj6 oXtqVzygFbLkaOkAzNRYkX4CYbghwDoezuJRj8inSqrWIlrPz8efnXX0v142M59w xIkoGiE1ciwgZ5+X+BYz9szPZ6lN47c9CYS3wQefKj3cijm14ZzhtDdwOOqTtFW0 B3OCcKjedsT65h0q/g6o5CZuOHQxdGNsf4yTfI7IsgPqr7qqt+h4R832BbLHqWH1 zg/kP1MlgtrP49smZlwyA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1668374687; x=1668461087; bh=rXPB6oe0xmPnWfhY9SUJZ9+wDPQU SDvtubRg8ZvXi6c=; b=rXtPyo1XALEuRTl4OFDnf6fQ1T/TgrQWLhWgWVuQfU4X dZhi9goiOoEM/kEiy8X1l23kzwNdL6ddz810+YEHDZRTanP9taZu2q5GAW+aOi6V 9rcusLDhnw0Na4VeO8KflVvNTNeH6sSz5ialeZl1f417SaGABtt2EFOtzde5v5c9 JVbkhFUDwRbEZ3MuCBRIT8ZKcor5B12otWBxqh/Rbc9hfnykMHO3C22/CpvQxp8g 4nz2jWUMjLhT1HT0qxn3bqeO9aHcyU5nfbSnpBMDGAhL3HUgK+FCO+veFRGuBkS0 KBFiIcSwrSNgMU5aOg54muVcX5I7BC1U13tof9yOXw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgedtgdduhedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id AE8E01700093; Sun, 13 Nov 2022 16:24:47 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1115-g8b801eadce-fm-20221102.001-g8b801ead Mime-Version: 1.0 Message-ID: In-Reply-To: <0854b030-c51c-4c1b-a7dd-22835a1e5da9@app.fastmail.com> References: <0854b030-c51c-4c1b-a7dd-22835a1e5da9@app.fastmail.com> Date: Sun, 13 Nov 2022 15:24:19 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Asymmetric Visibility, with readonly From: larry@garfieldtech.com ("Larry Garfield") On Sun, Nov 13, 2022, at 2:08 PM, Larry Garfield wrote: > Hi folks. Ilija is nearly done with the implementation for asymmetric > visibility and flushing out edge cases, but we've run into one design > question we'd like feedback on. > > There's two design decisions we've made at this point, both of which we > think are logical and reasonable: > > 1. If specified, the set visibility must be tighter than the get > visibility. So `protected protected(set)` and `protected public(set)` > are not permitted, for instance. > > 2. `readonly` is a "write once" flag that may be combined with > asymmetric visibility. If no set visibility is specified, `readoly` > implies `private(set)`, but a different set visibility may also be > provided. > > These are both reasonable rules. However, it creates a conflict. > Specifically, in the following cases: > > public public(set) readonly string $foo > > protected protected(set) readonly string $foo > > These would be the only way to have a non-private-set readonly > property. While the first is in practice quite unlikely, the second > has valid use cases. (In particular, a base class that provides > properties expected to be set by a child constructor, and then used by > a method in the parent class.) However, it would not be allowed under > the rules above. Working around it would require specifying `public > protected(set) readonly...`, which means exposing a property that > likely should not be exposed. > > That creates an odd situation where readonly and asymmetric visibility > may only be combined "sometimes." That is not deesireable. The only > way to combine them in their current form is to allow `protected > protected(set)` only if readonly is in use, which is excessively > complicated both to implement and to explain/document/use. > > We see two possible ways to resolve this conflict: > > 1. Relax the set-is-tighter restriction. That would allow `protected > protected(set)` etc. on any property. It wouldn't be particularly > useful unless readonly is being used, but it would be syntactically > legal and behave as you'd expect. We could still disallow "set is more > permissive" combinations (eg, `private public(set)`), as those have no > apparent use case. > > 2. Disallow readonly and asymmetric visibility being combined, because > readonly already has a hard-coded implied asymmetric visibility. This > option removes some potential use cases (they would most likely drop > the readonly), but has the upside that it's easier to re-allow at some > point in the future. > > 3. Some other brilliant idea we've not thought of. > > > Both are viable approaches with pros and cons. We're split on which > way to go with this, so we throw it out to the group for feedback. > Which approach would you favor, or do you have some other brilliant > idea to square this circle? Addendum: Ilija and I were talking past each other a bit, it seems. Allowing `protected protected(set) readonly` only in the context of readonly would be straightforward to implement. It's potentially not the easiest to explain that exception, but implementation-wise it's fine. So that gives another viable option to consider: 4. Allow get and set visibility to be both set explicitly to the same level, iff in the presence of readonly. So `protected protected(set) string $foo` is not allowed, but `protected protected(set) readonly string $foo` is allowed. This gives the most options and the least pointless syntax, but at the cost of having an exception that needs to be documented/explained/understood. --Larry Garfield