Member since
C#-inspired properties, yes please!
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.
I think this is very useful for PHP library developers.
They can add methods and provide a default implementation without breaking code (and if they only throw an exception).
For example Doctrine could add a addAll
method to the Collection interface and provide a basic implementation that uses the existing add
method under the hood.
Since interfaces (in other programming languages) don't add member fields, the this
won't need to be adjusted (by an offset) and the interface default methods just get added to the virtual method table (vtable) of the class, if they are not implemented by the class.
A lot of posts point out that JavaScript's syntax matches what's proposed here. If PHP remains a hold-out by not adding this syntax, it feeds the reputation that PHP is always behind the curve.
Marketability aside, i get sick of writing anonymous functions with use ()
statements where i need to make changes to an imported variable, and thus have to import by-reference. It's clunky, especially when references are so frowned-upon. To me it's much cleaner to have a short-closure where i know all data in scope remains in the same scope of that function.
I never understood the limit of one statement in the short arrow function syntax.
This seems to fix it and put arrow functions back on the level of the standard anonymous function.
So many times I had to drop array_map/reduce or similar functions just because I didn't want to use "classic" closure syntax. Honestly, I don't even see a big need in having the "classic" syntax nowadays, but having a multiline new-style closure looks very logical to me.
Prevents having to add a trait to every class that has to implement an interface, being able to provide default implementations via interfaces would be a large DX improvment
Most of the time when creating an Interface that shares some implementation we would always create Interface + Trait. This is just more work. With Interface default methods we would get rid of the Trait and be able to have it in the interface already!
it's works great in other languages like java and kotlin.