Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122478 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 052A41ACEBF for ; Fri, 23 Feb 2024 15:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708703912; bh=Wj9uEGeSWeWRgYaAlRl1UBDzyf8Fulsynf8nw/tTe90=; h=In-Reply-To:References:Date:From:To:Subject:From; b=hZXNJMIOFVHRQiYjrukx0gVNgseEd8VbOXoAlwCd7c5KHgoPsrV64HTkHQb6yI7KG 47XUyBrUrikEWhCJvxdu+2AOjyhKFoJ9qPnnzD0ViMIl/ySI7rlry3cgYyUFyRKFpl 4i2pAkj1K2j8ydCPDgm1A+ZoPZnXXgy3sJLY4X8jXdxLO0QAli42XrdmDrGC+eYyG7 6LBhr6VbkL1d2BSRdOdvpDDwAnoj8o1hTPCI2dOfzIZqn5CJjQqrN8ESCXhaGQK79A o75VIdOInBf3zzvyUIghFyKUKbB0y5n1WoDh/aE5M/BWp1WhrfNrqu+8iSmb8iqyk0 0g4rrYBEFWwiw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 479E7180047 for ; Fri, 23 Feb 2024 15:58:31 +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=-1.4 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, 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 wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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 ; Fri, 23 Feb 2024 07:58:30 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 7219D3200A0F for ; Fri, 23 Feb 2024 10:58:23 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 23 Feb 2024 10:58:23 -0500 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:subject:subject:to:to; s=fm1; t=1708703902; x= 1708790302; bh=E7XnUqajsZQSUrWx0LF7Dm3CkmPYTgZsYk/MqRKFeDM=; b=M YLzqcEXT9v6ChIEJdFMpJ+Jolsw6UvOBxxdt0UQ+7iZloKo9i6sWf6VzaryVY1gT 6kUg3Kyl3FSw5MWb/1xnbKAeNfYxWM3pEFmM9cWngjCofhbRkuk43HAbmt+vHtxD 72WGNP4N8AVDv0pv0zyESehobLq62/W2mhrk/RqoFM4+dgNK7Dc7vYXnH+giRp51 PUK8HpmL4Lk8SD0QKfeyMo/9yHW86eW/1ILD+fyvmYXEtxHoLTDA7r5JsWHVk4Yx zxOhVcHzQSasvJCZRz3lcNJvB8Bx5R74Ay5TMStfFcUy6xhGPVpzJSkerAK9RC1N SGUguYLDfJGHbwRcBRJMg== 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:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1708703902; x=1708790302; bh=E7XnUqajsZQSUrWx0LF7Dm3CkmPY TgZsYk/MqRKFeDM=; b=Z6rtVTvAIMYm7enVGj50KFrPo/jL2oIv5OC24YlaWtCG BY9iwPaTDe9GYF1YKS2x0vcd6A//ih22y9+gOfe7FVNs8CAnv0POWBLFs3juA9nw fDc2h50qUljB787tlswBTFluzjmp6ReIaYuVOHA1ActbWfahd7BNRvQQ6WbsYLym 43F0pCJMB20OduOm1g+nQP8i1MUgfveXL1rdnPGKaR4NbUWOfSHc8rL8NreatYMY /XRYBhm4rgT2S0U6s1aI3kJk9aEjkJKBmnIx2NAe4U5JHeJRV1KfEM2zG5m55bSy SWulEvmtvN1W89FyIHSPfOdFWz/3/+CLEI+pyZOKew== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeeigdekvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefgffek udevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 76CAA1700096; Fri, 23 Feb 2024 10:58:22 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-153-g7e3bb84806-fm-20240215.007-g7e3bb848 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <36e90d8d-d275-4ce9-9dd9-1e2422c6d3a9@app.fastmail.com> In-Reply-To: <52C6F501-8E23-42D7-8541-88A22AD79375@koalephant.com> References: <790b5b4e-f51b-4050-a12a-5fa903d0568f@app.fastmail.com> <52C6F501-8E23-42D7-8541-88A22AD79375@koalephant.com> Date: Fri, 23 Feb 2024 15:58:02 +0000 To: "php internals" Subject: Re: [PHP-DEV] [RFC[ Property accessor hooks, take 2 Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") On Fri, Feb 23, 2024, at 8:33 AM, Stephen Reay wrote: >> On 23 Feb 2024, at 06:56, Larry Garfield wrote: > Hi Larry, > > It's good to see this idea still progressing. > > > I have to agree with the other comment(s) that the implicit > `$field`/`$value` variables seem odd to me. I understand the desire for > brevity and the potential future scope of reused hooks, but this > concept seems to fly in the face of many years of PHP reducing "magic" > like this. The "magic" that PHP has been removing is mostly weird and illogical type casting. As noted, neither of these variables are any more "magic" than $this. However, since it seems no one likes $field, we have removed it from the RFC. Of note, to respond to your comment further down, $this->{__PROPERTY__} will not work. The virtual-property detection looks for the AST representation of $this->propName, and only that. Dynamic versions that turn into that at runtime cannot work, as it needs to be known at compile time. For $value, however, we feel strongly that having the default there is a necessary part of the ergonomic picture. In particular, given your comments here: > To give one answer to your question about ambiguity if the `$value` > parameter is required - I don't believe this is actually ambiguous, in > the context of PHP: > - method parameters in child classes don't implicitly 'inherit' the > parent method parameter's type if they don't define one (they widen to > mixed); > - method return types have no implicit inheritance, they must declare a > compatible return type; > - typed class properties don't implicitly inherit the parent type when > the type left off a child property - they must declare the same type. > > AFAIK there is no existing behaviour in PHP where omitting a type would > mean "the type is implicitly inherited from X", it either means the > same as mixed, or it's an error. That to me suggests that IF a custom variable name is provided, we should require also specifying the type. In which case, in the 95% case, if we require the full argument signature then the 95% case would need to double-specify the type, which is a hard-no from an ergonomic standpoint. Especially combined with the suggestion yesterday to allow return-to-set in the short-set version, that would mean comparing this: public string $phone { set(string $phone) => $this->phone = $this->sanitizePhone($phone); } To this: public string $phone { set => $this->sanitizePhone($value); } And to me, there's absolutely no contest. The latter has about 1/3 as many places for me to make a typo repeating the same information over again. Now imagine comparing the above in a property that's used with constructor promotion. public function __construct( public string $phone { set(string $phone) => $this->phone = $this->sanitizePhone($phone); } public string $phone { set => $this->sanitizePhone($value); } ) {} Again, it's absolutely no contest for me. I would detest writing the longer version every time. If PHP has been moving away from weird and inexplicable magic, it's also been moving away from needless boilerplate. (Constructor promotion being the best example, but not the only; types themselves are a factor here, as are arrow functions.) As the whole point of this RFC is to make writing common code easier, requiring redundant boilerplate for it to work is actively counter-productive. So what I'd suggest instead is "specify the full signature if you want a custom name OR wider type; or omit the param list entirely to get a same-type $value variable, which 99% of the time is all you need." We get that in return for documenting "$value is the default", which for someone who has already figured out $this, should be a very low effort to learn. > Also, a small nitpick: The link to your attributeutils repo in the > examples page, is broken, and it would be nice to see a few examples > showing the explicit version of the hooks. Link fixed, thanks. What do you mean explicit version of the hooks? --Larry Garfield