Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123566 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 3BDCC1A009C for ; Mon, 10 Jun 2024 14:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718029288; bh=tH28n34DUSd9xNOFug9rYKSz8aT+wRh5g1bAlJnKPw4=; h=In-Reply-To:References:Date:From:To:Subject:From; b=G/DprOKn8t00KuXylJ/L4XgnnTfpPMp8B3jVVtd7LLA5bH5X6YGU1m/JyQnvassuS 3PFwkxDuGdbKpk61/LzdtStVWStdZbcMfaLS4/BjuUiSVEZ2ElClJdzlApdtsXLNO9 1eQ3l9tisspA72thHVyScjEjbbQdowEJncNT9e/d3Jrr2AIyn91eFJ3hdqlPdqEOnP gfRaMZFGFr/yBe36QRGBoSIq2WRHZNgYKIZXgUQmaDJFtTBhVwWBODL5NlcM82O5BD vMBgpdrPbmIX3AJhiBcwdLEvTjOQNk8vSXR9554OvRIIQYV9X+DCgC2rmF1fPLXVqC y5D/HfCRxz6gQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A5F81180081 for ; Mon, 10 Jun 2024 14:21:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 10 Jun 2024 14:21:27 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id F391011401E2 for ; Mon, 10 Jun 2024 10:20:18 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 10 Jun 2024 10:20:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1718029218; x=1718115618; bh=DIpew1FfGSgjabKLFbU2d THZdLwx/XAmoCIP0/1n1Bc=; b=HkG83jCpatH8A7z9rfiiWCYWzXIXaNIOJOROJ e+YLEAsdbUikXhGpy276qFHVh4uQfNE9IRiDBTnQnY7pAD41YPGgRFNDELsPO+ul J5KmuMG3FawPihlN1k37IZmw6Ep38yXTWBDQaBE+bk4ed9n3nCVodC4U8tPXhbBP 28oBuVxDa9W+Ppvj2vQWKWzKer+N2xQKuv6P9MuvCjVJsL4UvSyqEto/H1tpdXdG pNy9VKFg/LAyM36Hetny6Q837S4tM4ZR6Z5JcpDCahxv8+7w9gE8ZCJ2woN3PriV Uw60wEKxVTHm/THFecdvMvztXkBmQZPgEfvwh+pZfEbadVkrg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718029218; x= 1718115618; bh=DIpew1FfGSgjabKLFbU2dTHZdLwx/XAmoCIP0/1n1Bc=; b=O yXSPaimesBP4z47XUCZ+whTslEybToV1dkqLmtwc116OxRDCA1dgqX0hFBYfLyvj pGZoxDGEqTNzTkdZSRmbAJKzXLlQ7IO/6OaYda7K/Jk19JBp2TV61RlCuD4/DBL1 MB3RnQSlQtMoeOKHIePlc/oIrnc9TXULVgchKVkwX+YTuCtU6eimroqirXjYHYMI 0KW6PTZwSRwXdX93FxrngK0AoyoJNzUL6yY9rn73SU+QpddCPAlqVIa1lafdZaZp EfuBbjd6b5ua/byIrqMfGYqBA3LCbhgWlfYs5bYRowJ63+Hivw4DXNz9RsVmcPQH 9IcH7qTMtzofr19xGz7WA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedutddgjeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeeghefgteejheeggfeghfelueeggfdtjeeivedv tefhveeguedufeelhedvteeinecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf ihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 818C31700093; Mon, 10 Jun 2024 10:20:18 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-497-g97f96844c-fm-20240526.001-g97f96844 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: <834cb6c7-c6ae-4b59-b022-a43793f842a3@app.fastmail.com> Date: Mon, 10 Jun 2024 14:19:38 +0000 To: "php internals" Subject: Re: [PHP-DEV] [RFC][Vote] Property Hooks Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Mon, Jun 10, 2024, at 12:33 PM, Valentin Udaltsov wrote: > On Sunday, 9 June, 2024=E2=80=AFat 19:03, Nikita Popov wrote: >> __ >> On Mon, Apr 15, 2024, at 18:43, Larry Garfield wrote: >>> The vote for the Property Hooks RFC is now open: >>>=20 >>> https://wiki.php.net/rfc/property-hooks >>>=20 >>> Voting will close on Monday 29 April, afternoonish Chicago time. >>=20 >> The other thing that stood out to me are the short-hand notations usi= ng =3D>. There was a prior RFC on the topic (https://wiki.php.net/rfc/sh= ort-functions), which has been declined. That RFC would have introduced = =3D> ... as a general shorthand for { return ...; }. >>=20 >> The shorthand notation for get is compatible with that formulation. H= owever, the shorthand notation for set is not. In that case =3D> ... isn= 't short for { return ...; }, but rather for { $this->prop =3D ...; }. >>=20 >> This seems pretty unfortunate to me, and possibly closes the door on = revisiting a general short function syntax in the future. Mostly I'm scr= atching my head at why this was included in the proposal at all, as I wo= uld not expect this use of the set hook to be common enough to justify a= shorthand. The common case is a guard that checks the value without mod= ifying it. I'm a little surprised to hear you say that, since you voted against sho= rt-functions at the time. :-) I would love to try again on those if the= re's enough change in opinion to make it worthwhile, as I do think it's = useful. The reason we included short-set, aside from consistency, is that people= really seemed to want a "return to assign" behavior, and that was the m= ost logical way to do it. It's also more compact for when a set hook is= inlined into a promoted constructor property, which I suspect will be n= ot uncommon. For "validate or error" use cases, a ternary isn't ideal b= ut it will get the job done, and there are several examples of that in t= he RFC. If we find that "validate but don't modify" is an especially common case= , then we should look into a more dedicated syntax for property Constrai= nts / Guards. (I have some ideas there, but nothing ready for public co= nsumption.) I don't think the current hook syntax would preclude short-functions gen= erally, though. The syntax is the same, the behavior is the same, all t= hat's really different from the typical case is the extra "and the thing= it evaluates to gets assigned." Which is exactly what several people a= sked for. So I don't see how it is really going to cause a conflict. (Side note: If anyone has warmed to short-functions since it was last br= ought up let me know. I have no idea how to gauge if the zeitgeist has c= hanged since then to make another attempt worthwhile.) >>=20 >> Regards, >> Nikita > Correct me if I'm wrong, but here's how I understand the short-hand=20 > notation in setter hook in combination with=20 > https://wiki.php.net/rfc/short-functions: > > ``` > final class Foo > { > // Before > public string $x { > set { > $this->x =3D $this->transformX($value); > } > } > > private function transformX(string $value): string =3D> trim($valu= e); > > // After > public string $x { > set =3D> trim($value); > } > } > ``` > > So it's kinda consistent if you say that only the right side of the=20 > property assignment is replaced with short-hand notation, not the whol= e=20 > assignment. And then `$this->x =3D` is implicit. Essentially that, yes. --Larry Garfield