Re: [RFC[ Property accessor hooks, take 2

From: Date: Thu, 22 Feb 2024 19:39:11 +0000
Subject: Re: [RFC[ Property accessor hooks, take 2
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-122473@lists.php.net to get a copy of this message
Hi On 2/22/24 00:02, Matthew Weier O'Phinney wrote:
Once again in reading the proposal, the first thing I'm struck by are the magic "$field" and "$value" variables inside accessors. The first time they are used, they're used without explanation, and they're jarring. […] Second: you don't have examples of defining BOTH get and set OTHER than when using expressions for both accessors or a mix. I'm actually unclear what the syntax is when both are defined. Is there supposed to be a ; terminating each? Or a ,? Or just an empty line? Again, this is one of the more common scenarios. It needs to be covered early, and clearly.
On a similar topic with regard to syntax and shorthands, I'd like to quote myself from my previous year's email (Message-ID: 17d7983b-68b7-e273-a445-f8399c2510cc@bastelstu.be, https://externals.io/message/120213#120216):
(5) I strongly dislike the doubly abbreviated form of public string $fullName => $this->first . " " . $this->last;. Having just the extra '>' in there to distinguish it from a regular property feels non-obvious.
It's always possible to follow-up with syntax that allows for additional brevity, the inverse is not true and I believe for such a semantically complex feature, having clear and syntax syntax would be beneficial. Best regards Tim Düsterhus

« previous php.internals (#122473) next »