I find this syntax pretty messy, to be frank. Maybe it's a good idea (since it is available in "modern languages"), but not something I would use much or even recommend using...
This is a much better approach than having to create getters and setters for validating values before assigning them to properties. Actually, this is an aspect from C# which I really like...
In combination with Asymmetric visibility this will allow to replace all getters and setters with trivial properties and occasional hooks.
This is good to have.
Properties are useful for exchanging (reading and writing) single values. Properties are good for data binding, etc.
With this RFC we can implement:
Update: About the $field I am not sure. Having a separate backing field can have some advantages.
This definitely makes life easier. I find myself writing a lot of anonymous functions for commands like array_map, array_filter and so on... and it really makes me sad when I realise I need to have a multi-line function body and need to get back to the default function syntax. It's a simple yet very useful feature PHP could have. Actually, I don't mind keep using the syntax like fn() =>
as far as it supports a multi-line body and bypasses the need for the use(...$vars)
command which is also kind of annoying.
We spend a lot more time reading code than writing it. The elegance of short closure combined with the convenience of variable scope usage has already shown to be a game changer on Typescript and there doesn’t seem to be any technical issue with having it on PHP.
At least once a week, I throw away an array_map because it ended up looking too bloated and go with a classic foreach instead. Short Closures 2.0 without the use(...) block would've solved this problem, just 2 votes...