Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120304 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 17728 invoked from network); 15 May 2023 21:06:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 May 2023 21:06:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5AD2E180083 for ; Mon, 15 May 2023 14:06:47 -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,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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 ; Mon, 15 May 2023 14:06:46 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C0D075C00F2 for ; Mon, 15 May 2023 17:06:45 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Mon, 15 May 2023 17:06:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type: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=1684184805; x= 1684271205; bh=9nTZ6cW5V80L3S89/mvTRW4GckTYOirNzqNTM2xq9W4=; b=m Xhp/uT/3myU6fDNWIli4Ybm2eWI9I+z4K/Pj0MMrdkKbRNq0LH/Iw+c22n9DTyix nX+LFGS5Z5A5zdnbPOQp83xEeMe0VtW+LjEDVZ+Zxw8bg5xryqQsoxe3omT8qLxN Saigk89dfpHuNlsyJBppb6fhxpm6DGym3+hBai/hgDK+CAOFR7xQTpENiZSqVN2x CmhJOvuyZ7G0Kmu7P91sGZNWeMwjeA4Akeu2sRBrqCTeKSLujF5xQLUpuGTYeiF0 fm6Q5YkVgRJa8YIi/GGBNK9zExmL0gpEVBoV0bw+9zFjIIY98wsCk3vV9Y3puoMF 7mM0zhk7Bfrck9eluTl/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type: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=1684184805; x=1684271205; bh=9nTZ6cW5V80L3 S89/mvTRW4GckTYOirNzqNTM2xq9W4=; b=qW30SYwl7pCZN6ZCgYyrePeB89mHz YzmvBO8hyYj5Prdfib5WyZUvqKw35pDqrkWgBnkcDXyBoWqvCPP4yvn3qE6ctGY6 aNAfjTD2HOPOlUw2W3K9HImZ7QJSKRu77rpxwh8MPbMGWDGa46FRkRsD6lvhwB4H ac09v6E2gbxpcsNgQ/TDLLfvaKhCwz3vhmJfu/uyfuyUcvLA4y9AdHurd2JMfBpv iCox1sVZTyCvVVQ9fyaRUkZCZ+BrFfJ21VC/Srrl/PNhyJKTWxlG2V/+BeLYCUgN OwFvVJEzJPW4iviFUo7+M5Rr9TQrlJ6IHUh4OLEf41v2giqhY0EBOch5w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeehjedgudehlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 81B761700089; Mon, 15 May 2023 17:06:45 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-415-gf2b17fe6c3-fm-20230503.001-gf2b17fe6 Mime-Version: 1.0 Message-ID: <4947b8d1-1c1d-445d-ba9b-a21f21772548@app.fastmail.com> In-Reply-To: References: <641b1ca0-d33f-4f38-ae64-81b4abce24da@app.fastmail.com> Date: Mon, 15 May 2023 21:06:25 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Property hooks, nee accessors From: larry@garfieldtech.com ("Larry Garfield") On Mon, May 15, 2023, at 8:12 PM, Hendra Gunawan wrote: >> For the second, the problem with omitting the {} is that it creates yet another syntax variant. That makes it harder for the parser, for static analyzers, for user-space parsing tools like php-parser, etc. That's more work for everyone for fairly little gain. > > Sad to read that. Making one of them as the shortest shorthand feels > like a picky decision. Some people agree with ```get```. Some people > will argue that ```set``` deserves more than ```get```. Personally, I > choose ```set``` to be the shortest shorthand as it is more relevant > with constructor property promotion and value object. Do we need a 2nd > vote for this one? Secondary votes are generally discouraged. I can see the argument for wanting a short-short version of set, given how common the validation use case is, but => is almost universally the "evaluates to" symbol, so using that for a set operation rather than get just feels weirdly inconsistent. If there were a set-only shorthand, it should be something else. That said, the ideal for validation would probably be guard clauses, like this, but that would be a completely different RFC for another time. function foo(string $name where strlen($name) < 10) { ... } class Foo { public function __construct( public string $name where strlen($name) < 10; ) {} } >> What we really would need here is asymmetric visibility. No set hook, but make the property private(set) so that trying to write to it gives an error, as it should. > > So if asymmetric visibility is implemented, will my code be this simple? > ``` > // cache once and freeze, > // and without additional hidden property > public private(set) string $prop1 { > get => $field ??= $this->heavyTask($this->propx, $prop->y); > } > ``` If you don't want cache clearing, yes. Ilija also noted to me off-list that you could also have a set hook that throws an exception rather than just being null, which would also work to prevent writes. For clearing that cached value, I think an unset hook is probably the best way, with either approach. >> For cache clearing, the best way to do that is probably with an unset hook. That's been omitted from the RFC for now for simplicity, but that sounds like it would be an argument to introduce it later. > > I was going to write about this one. IMO, why do we need to provide > additional hidden properties, when we are able to store the cache > directly into it? Obviously we need a ```unset``` hook. I think an unset hook is a fine addition in the future. The way the code is implemented it should be straightforward to add. However, it feels like scope creep to include it right now, especially when there are workarounds available. If there's a clear consensus from voters to include it, though, we can consider that. (Meaning, anyone that would favor including an unset hook now, speak up or we'll assume it's better to stick with just get/set for now.) --Larry Garfield