Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118550 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70377 invoked from network); 31 Aug 2022 23:59:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Aug 2022 23:59:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DDB241801FD for ; Wed, 31 Aug 2022 16:59:45 -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.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 ; Wed, 31 Aug 2022 16:59:45 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 0FE6E3200437 for ; Wed, 31 Aug 2022 19:59:43 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Wed, 31 Aug 2022 19:59:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=1661990383; x=1662076783; bh=91MmFLPglZRnammCbrkkVO54d pO18JryroG50fzUiHk=; b=gNF/qmxxD0pYhZGgZ/YQluHUj47IDucij6T9qtayf GFHx7TT2hSN53r1GORr/nno1YjMa+yuIdKK4rWY0t33HCrB4Cv1gKzP/9x152S68 JP+N8QqMfMycW0oxP1nwxsrhcQ40MyElAELynA1QcajJuEZGPUSh6+AT75edwWY6 oAUJqjFmYqIVkzJy7PNZNo7XGY2VclgpzQhtPHxZ1527QKl+arGVhAObwR0gFR5X bpfqGWjXA5WBmYBMdg6WUKcw4M5feNd7XvndivRC9Fm6HneFBpzbuvnWk7y8UAZc 2bozHouXxcIeGJZJwf/N0G3XdkJvQgWBnCCluw7jDqZlg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=1661990383; x=1662076783; bh=9 1MmFLPglZRnammCbrkkVO54dpO18JryroG50fzUiHk=; b=gG0RUzWjXi3prGMtX lSesbYQZtVaLvMVFJ2PVav3sTYe4zGbIS3tJpgleyJvMtLQD+7xpfPv8/aejvDGh Ur6rUSpZ71txNuUWLxLfUbR1mZcgOvTbTrP5txjg7Yxf7ZJKyY2QbdD1iO4uM3K9 QKz/EsqANmbT9B9NMr9bskHD8zx3YydIhxxFpyqA/Y6D3lBM2xChUg6XK7thPFbu /AV0pw6Dsw6oMimYg+Y/4CD/ViWiyemCIE+JqMsUDhnuCbZ1aMPNg3jM46voVLhf TSlN3jBP3Zy+9JS+NBsMSlomaRjZwOy5o33E+Zjkhz6WPxgPEOBn0OeflHrqgdtU n4Smw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdekjedgvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 34F2B1700084; Wed, 31 Aug 2022 19:59:43 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-841-g7899e99a45-fm-20220811.002-g7899e99a Mime-Version: 1.0 Message-ID: In-Reply-To: <8fd0c415-181d-0d2d-da1c-2f71cfdc40c8@bastelstu.be> References: <81b41335-afa1-40b7-9eb6-4664304812ec@www.fastmail.com> <8fd0c415-181d-0d2d-da1c-2f71cfdc40c8@bastelstu.be> Date: Wed, 31 Aug 2022 18:58:45 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Asymmetric visibility From: larry@garfieldtech.com ("Larry Garfield") On Wed, Aug 31, 2022, at 4:26 PM, Tim D=C3=BCsterhus wrote: > Hi > > On 8/31/22 22:43, Larry Garfield wrote: >> ## References make everything worse >>=20 >> [=E2=80=A6] >>=20 >> That problem wouldn't happen if all we're changing is visibility, how= ever. That means in the C# style, we would need to differentiate whethe= r the block on the right is intended to disable references or not. Ilij= a has proposed `raw` to indicate that. That would mean: >>=20 >> ```php >> class Test >> { >> public $a { private set; } >> public $b { private raw; } >>=20 >> public function inScope() >> { >> echo $this->a; // echo $this->getA(); >> $this->a =3D 'a'; // $this->setA('a'); >> =20 >> echo $this->b; // echo $this->b; >> $this->b =3D 'b'; // $this->b =3D 'b'; >> } >> } >>=20 >> $test =3D new Test(); >>=20 >> echo $test->a; // echo $test->getA(); >> $test->a =3D 'a'; // Error, set operation not accessible >>=20 >> echo $test->b; // echo $test->getB(); >> $test->b =3D 'b'; // Error, set operation not accessible >> ``` >>=20 >> The take-away for the asymmetric visibility only case is that we woul= d need to use `raw` instead of `set`, in order to avoid confusion later = with accessor hooks and whether or not to disable references. >>=20 >> The Swift-style syntax, as it does not require any hook-like syntax t= o just control visibility, does not have this problem. There is no ambi= guity to resolve, so no need for a `raw` keyword. >>=20 > > I've read through that explanation three times, but don't understand w= hy=20 > the C#-style syntax would require to differentiate between `set` and=20 > `raw`. Isn't the difference between "visibility only" and "accessor" n= ot=20 > clear [1] by having either '{' or ';' after the 'set'? > > [1] Read: Clear to the engine, not talking about the human reader here. Yeah, it's complicated, and Ilija had to explain it to me several times.= :-) The tricky part is that there's *three* different toggles involved here. 1. Asymmetric visibility. 2. Accessor hooks. 3. Disabling references on properties. Invoking 2 necessarily implies also doing 3, for reasons given above. H= owever, we also want people to be able to enable 3 on its own, so that I= F they enable accessor hooks later, it is transparent and doesn't imply = breaking references unexpectedly. (Viz, you could have a value object f= ull of `public string $foo {}` type properties, which disables reference= s, and then slip in a get/set hook later and no one notices.) So we need a way to indicate "I'm using a-viz, and disabling references"= as well as "I'm using a-viz, and not disabling references." With the Swift style syntax, that's super straightforward. public string $foo; // No a-viz, references work. public string $foo {} // No a-viz, references disabled. public private(set) string $foo; // a-viz, references work. public private(set) string $foo {} // a-viz, references disabled. And the {} makes a convenient marker because you'd be adding it in the f= uture anyway if you add hooks, which would force disabling of references= . So it's a natural flow from one option to the next. With the C# style, a-viz means you're *always* putting braces on the rig= ht, so we cannot do that. Instead, you need public string $foo; // No a-viz, references work. public string $foo {} // No a-viz, references disabled. public string $foo { private raw; } // a-viz, references work. public string $foo { private set; } // a-viz, references disabled. So then the toggle for disabling references is "there's a set or get key= word inside the braces", but we then need a different keyword for "I'm *= just* doing a-viz, and I don't want to disable references." Hence, "raw= ". (I'm assuming in the above that Ilija is able to make omitting the "get;= set;" if there's no body for them. He's reasonably sure we can but hasn= 't confirmed it.) Is that clearer? --Larry Garfield