-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New PHP 8.4 Syntax: Property Hooks #88
Comments
Unsurprisingly, my recommendation is for the style used in the RFC. Including allowing get to be all inline if it's an abbreviated get. public string $userName { get => $this->user->userName; } |
That brace placement would be inconsistent with methods, which have a newline before the opening brace. |
That's true. However:
|
Sorry, but that really is a non-argument. People read and evaluate RFCs for the functionality which is being proposed. The code style used to present that functionality is absolutely irrelevant to an RFC and discussing that on the internals mailing list would be waved away within seconds.
The language used here is pretty strong and IMO comes across as disrespectful to the people involved in that decision. Whether you agree with decisions taken in the past or not, is irrelevant. Code style is all about consistency and making thing easier to read. Advocating for deliberate inconsistency just because you don't agree with a past decision is not a good argument to back up a proposal. If you don't agree with a past decision, challenge that decision and propose to change it, but don't make a code guideline inconsistent. |
Just my 2 cents and my heuristics on the matter having read the RFC, played with the 8.4RCs and prepared a couple of slides with code examples for talks. Instinctively, both examples discussed here feel formatted correctly, the longform example only feels correct because I prefer braces on the same line for functions. Which clashes with how all other code looks. LongformWith that in mind, I'd say for this standard to be consistent, the formatting could look like this: public string $userName
{
get
{
return $this->user->userName;
}
set (string $name)
{
$this->user->userName = $name;
}
} Which I find very lengthy personally. public string $userName
{
get {
return $this->user->userName;
}
set (string $name) {
$this->user->userName = $name;
}
} Feels more natural like a “function” (string $username properties) and an inline statement “get” inside that “function”. Short closures / Arrow Syntaxpublic string $userName { get => $this->user->userName; } Also feels ok and fitting to me.
Short closure with more than one accessor.My main question would be on using both a set and a get with short syntax. The new line after $userName again feels fitting with the rest of the standard, despite my person preference. public string $userName
{
get => $this->user->userName;
set (string $name) => $this->user->userName = $name;
} SummaryFor me, the above feels consistent with how we treat single element arrays vs. multi-element arrays. Reopening the discussion for this standard on “new line before |
Property hooks are landing in 8.4, the next version of PER-CS should cover them:
The text was updated successfully, but these errors were encountered: