Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122482 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 B1B9A1ACEBF for ; Fri, 23 Feb 2024 21:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1708722057; bh=V63APJm2wn+5XJmu1A8k8rzRKDw+mOAzc03upMTR21A=; h=In-Reply-To:References:Date:From:To:Subject:From; b=RjEH6pcq8eFtrlqIYI34CpAXGTLR7b94X6QcITQ2SPFvsaDGZmcUt+gS20DsJk2MC 5BZdkiXfF6camVE8eUXQUJIfiSm4JziJjrxji1iPh/qgzMc5O0D9YuSAL5KJkuylVe XETyl9D7p7ZhqEMCpDB4G0afbC2TeIKZWNg7amSCAM3kwh6KjVn/LfkLAWzB5cOGTZ EFzq7BE/4QSF497V7wr8bQxL/Z29Uxm6l1Lqj7TyHyeHm/cZo1b2tqCL5mnkJD+79n wnYxRWTY3T03WffGQ0S58ImqR0r1em2Uq+tmB80NbE3FqdwQjlzLYkH7L+W49xh38y R4coaeTOo5WbQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4F46C180567 for ; Fri, 23 Feb 2024 21:00:56 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 23 Feb 2024 13:00:55 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id A961B3200A3E for ; Fri, 23 Feb 2024 16:00:48 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 23 Feb 2024 16:00:48 -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=1708722048; x= 1708808448; bh=0OWqN0cibZvNndlcXzG6nhQyijTwSH0j83CLPG7mbJY=; b=f nvL2uztAvcrBWGqkXhoyjrtxgebkpeLQgtTzRt9xFl3j39hhxohhrjqhOHabiRrI GIQjV2tyuBUzlhBWzwZqzc9rJYONiUzRZdL9sxJdpApL+FCSq0mgO3NM1G/+w0yr eIcZn9A4VHR9Mu1U9/mIBWoxhQLBZh0TvV53ViaaqNg/o8O/+s/d0W0qqWxEqXBn qDoMY2z7YpShK5XtlGn+hqCDy19qACuSw60h07/558Zs/QnAfo/6rdJqBUyXCutg MbCHM2BaE+p2r02SCOY4Ty17ZxoJbOwprmjhXrHa7MXrKce81zeVK86UzUZwgyBU MXEHlP/mGLHC8Z+r8Ry/g== 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=1708722048; x=1708808448; bh=0OWqN0cibZvNndlcXzG6nhQyijTw SH0j83CLPG7mbJY=; b=EHGDBsnB/C3/AOLlJTbgP2U08ZqTKQ6FBC4sn659YTTR /XPXlhxZYpPMEtiZ3XvhWojLekihhCSFuFf2b6wwvwLf9MzLIRfqJ/PH7/hTkCYb bZrcruHiTeqVJ3MU5GLcGwqAVi3vpMFsAei2EarPK8x7eaOAlfXZHnFhSMmbnpFz V2EOVPBLnLeS/RW5sTsRsUnxQOS9V2+9tUNzsbweNDP+Hqt5p9+uHebHx4mvgOFN 46VP1gVoEi1ITT0WEPLemuMu2xMWw/D5L4y+Ec3iVhZDSLTItvZjCat7yLpdUhDa nvSZFQ2svO+ma3dm8EmrczVUDKh4OuDo8y+XUCFNUA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeeigddugeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id BCE271700093; Fri, 23 Feb 2024 16:00:47 -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: In-Reply-To: References: <790b5b4e-f51b-4050-a12a-5fa903d0568f@app.fastmail.com> <52C6F501-8E23-42D7-8541-88A22AD79375@koalephant.com> <36e90d8d-d275-4ce9-9dd9-1e2422c6d3a9@app.fastmail.com> Date: Fri, 23 Feb 2024 21:00:26 +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 4:50 PM, Stephen Reay wrote: >> On 23 Feb 2024, at 22:58, Larry Garfield wrote: >> >> 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. >> > > I guess it's mostly irrelevant on single-use hooks anyway, but that > sounds like a potential gotcha with reusable hooks, and I think it's > worth making it very clear *now* in the RFC/docs that dynamic access > like this won't work as expected (and why). Perhaps some other > indicator on reusablele hooks can be used at that point, to signify if > it's virtual or not. Look, we can have a common variable that can be used in all hooks, or we can minimize the "magic" names. We can't do both. Make up your mind. :-P It's already been included in the RFC that only explicit property name usage will work. As noted, reusable hook "packages" a la Swift is a potential future scope. At that point having some common variable name is probably sensible, but we can color that bikeshed when we get to it. >> 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: >> 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. >> > > I think you're making slightly misleading comparisons there, by picking > the two extremes (and ignoring the possibly for shorter explicit names) > - the explicit parameter name surely doesn't preclude the use of > return-to-set functionality? So the comparison could equally be: > > ``` > public function __construct( > public string $phone { set => $this->sanitizePhone($value); } > public string $phone { set(string $v) => $this->sanitizePhone($v); } > ){} > > ``` Yet nearly all coding standards and recommendations (outside of Go) say to not use single-character variable names, so I wouldn't expect that to be common. Even if it's not as big of a difference, it's still two places to specify the type and two places to specify the variable name. That is, two places to get either one wrong. Constructor Promotion is one of the best features of PHP 8, precisely because it eliminates that kind of duplication. I see no reason to mandate redundancy and duplication in code. >> 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. > > I get your point, and to expand on what I said in the first email - if > removing the implicit mode would mean people vote against the RFC, then > that's a worse result, IMO (this is why I suggest a secondary vote - > perfect is th enemy of good and all that). I personally think the > implicit variables will result in less-readable code, but I also know > that I'm free to not use the implicit parameter in code that I write, > so I trust those with a more accurate finger on the pulse of the voters > to know whether the implicit `$value` parameter will help or hinder the > RFC to pass. As has been noted numerous times, there is basically zero way to tell what people will vote before they do unless they explicitly say so on list, and the list has had maybe a half dozen voters comment at most. So, I truly have no clue if $value is the pass/fail trigger for someone, or which direction. This is a long-standing issue with the PHP dev process that Internals has shown no desire to address. The problem with secondary votes is that they come off as "meh, I couldn't be arsed to decide here." Based on comments on the list, some non-small number of voters see secondary votes as a good "crowdsourcing" answer, and another non-small number of voters see them as abdicating responsibility and want opinionated RFCs. I have no idea which to go for. :-/ But in this case, the opinionated RFC position says "making people type the same things multiple times on every usage when there's no reason to is silly." >>> 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? > > I meant hooks that don't use the implicit "magic" variables (i.e. > specify the parameter on set() specify the full property name when > accessing the backing store). Given your first response I guess this > request is a little moot, assuming the examples are updated to remove > use of `$field`. Maybe the RFC or an example already covers it and I > skipped over it, but it'd be good to make it clear *exactly* what the > equivalent of an implicit `$value` parameter is. Once others weigh in on either of the proposals I've made in this thread, I can update the RFC accordingly. --Larry Garfield