This RFC proposes a way to have multi-line short closures — closures that don't need explicit use
statements, but can still have multiple lines and a return statement.
it will increase code readability to sky)
Just for the sake of code readability improvements & not needing to use the use keyword, It has my full support. Other languages have solved the issue, why not PHP aswell?
use(...) can be shortened easily.
Would love to have the elegance of short closures in PHP 🙏
Being possible to create closures that share the scope would be a game changer because it would mean less work and headaches with the use() block that in some cases if you don't pay attention it could lead to a lot of time waste on refactors and maintenance in code.
I think that with this, we would be able to write cleaner code that's easier to understand!
As many have already said, this is a common feature in other languages. As it stands, PHP has a half-baked version of short closures since introducing arrow functions. This is the natural next step.
It would be far more convenient, especially when code that starts as a short closure needs to do more, which is often the case, temporarily, when debugging. It will also help developers coming to PHP from other languages. I don't often find value from use ()
scoping either, but we'll still have the option when needed.
It improves the readability and usability of closures
Arrow functions in PHP were an awesome addition and I would not work without it today. I wish we had the multi-line version.
Another (extended) syntax for anonymous functions. We do not need to apply closures on everything.
its modern
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.
Short closure is a trendy syntactic-feature in many languages this days. It's easier to write and read.
I love this proposal. It basically makes closures up to date with other programming languages, and is sorely needed in my opinion.
as often, it's more for a question of readability that I vote "no"....I prefer by far a good code more readable than shortcut solutions
The "pipe operator" |>
allows you to chain multiple function calls in a more convenient way.
A new syntax for declaring the “set” operation visibility of an object property