Short Closures 2.0

Read the RFC
98
368 yes
65 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%
3

Classic closure is perfect for this kind of use case

Share:
degraciamathieu avatar
degraciamathieu
voted yes
2

I don't understand "no" voters arguing about readability when use (...) is the one statement decreasing readability.

Voted "yes" because I think the opposite :

fn ($something) {
	return $somethingFromOuterScope . $something;
}

Is easy to read... $somethingFromOuterScope can not come from anywhere but only from the most close outer scope...

Share:
trehinos avatar
trehinos
voted yes
2

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.

Share:
thookerov avatar
thookerov
voted yes
2

I don't see the advantage. Use short closures for oneliners but this rfc makes it complicated and messy

Share:
uli avatar
uli
voted no
2

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.

Share:
agc avatar
agc
voted yes
2

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.

Share:
ozahorulia avatar
ozahorulia
voted yes
2

The use statements are usually what is keeping me from using the short closures, so having this resolved would make life a lot easier in those cases and the code cleaner

Share:
Carakas avatar
Carakas
voted yes
2

Definitely will make our lives much more easier.

Share:
tiago avatar
tiago
voted yes
1

.

Share:
cverond avatar
cverond
voted yes
1

Just why not :)) No one was forced to use them, but when it's introduce it has many useful applications.

Share:
arziel avatar
arziel
voted yes
1

Short closures are definitely needed!

Share:
lkankowski avatar
lkankowski
voted yes
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
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!