Short Closures 2.0

Read the RFC
101
373 yes
66 no

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.

Click the bar to cast your vote!
85%
15%
1

Would prove very useful in more complex array_map or array_filter usages

Share:
cjfulford avatar
cjfulford
voted yes
1

Syntax similar to default, without use statement and short for "return".

function($item) use ($baz) { $this->foo($item + $baz); return $this->bar($item); }

to

fn($item) { $this->foo($item + $baz); => $this->bar($item); }

Share:
ondrej-vrto avatar
ondrej-vrto
voted yes
1

Every major languages had this long time ago. Why is this still the subject for discussion, I don't understand. I don't think it affects performance of the language.

Share:
uchm4n avatar
uchm4n
voted yes
1

improves readability

Share:
ismaail avatar
ismaail
voted yes
1

This makes code much more readable and beautiful. I think the last line can be returned without having the return keyword like ruby and some other languages.

Share:
mokhosh avatar
mokhosh
voted yes
1

it just a good next step towards clean and readable code.

Share:
gertvdb avatar
gertvdb
voted yes
1
Share:
undjike avatar
undjike
voted yes
1

It will make php more consistent

Share:
bronek89 avatar
bronek89
voted yes
1

The point of short closure is to be one instruction only, plus you can already have the body of a short closure on multiple lines.

Regular closure can do multiple lines and instruction already.

To me this is a tiny syntactic sugar that is really unecessary.

Share:
florentpoujol avatar
florentpoujol
voted no
1

would make the code more readable, instead of the need to pass multiple parameters through the use()

Share:
andreas avatar
andreas
voted yes
1

I thought short closures 1.0 was a step in the right direction, I would like to see this continued.

Share:
sam-moffat avatar
sam-moffat
voted yes
1

seems obvious

Share:
letssurf avatar
letssurf
voted yes
1

Not a fan of closures.

These things can be useful in specific cases, but as i've seen someone else mention aswel shouldn't be used carelessly. In my opinion closures, especially when scattered throughout a codebase, make code hard to read.

Hiding scope makes this even more dangerous. It shouldn't always be about "faster to type", "less lines" or "doesnt require me to think". We should make sure everyone is able to work together on a codebase, we can do that by being explicit.

Please don't make javascript 2.0.

Share:
vslokker avatar
vslokker
voted no
1

Small but nice QoL improvement

Share:
sandermuller avatar
sandermuller
voted yes
1

I always hoped it would work this way

Share:
harasimowiczkamil avatar
harasimowiczkamil
voted yes

Check out another RFCs

Interface Default Methods

Interface Default Methods improves backwards compatibility when changing interfaces, but also add a way to have multi-inheritance in PHP.

95
168 yes
264 no
Property Hooks

A new way of interacting with properties

70
141 yes
90 no
Asymmetric Visibility v2

A new syntax for declaring the “set” operation visibility of an object property

21
21 yes
38 no
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!