Scout APM helps PHP developers pinpoint N+1 queries, memory leaks & more so you can troubleshoot fast & get back to coding faster. PHP 8.1 is already taking shape quite well, yet there's one feature I'd love to see added, that's still being discussed: multi-line short closures.

A quick refresher, this is what arrow functions in PHP look like today: And this is what the RFC proposes: There are two important things to note about multi-line short closures: You might have already noticed it, but the RFC introduces an elegant kind of symmetry in how you can create closures: Because of this symmetry, all of the following code samples are possible and all of them behaving a little differently.

First, auto-capturing is already supported by PHP in the current short closures, there's nothing about this RFC that changes that.

If you want by-reference passing, you'll need to specifically say which variables you want access to — which is exactly what function allows: I'd argue that this RFC creates clear boundaries between what's possible with function and fn.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners