Short Arrow Functions Approved By PHP

  • Share this:
Short Arrow Functions Approved By PHP

Lots of developers (like me) have been a fan of the short arrow function usage since their addition to programming languages. In JavaScript, it has helped make coding functions/closures more concise.

An RFC was proposed earlier in March 2019, which overwhelmingly passed with 51, "yes" against 8, "no" votes. Voting ended on May 1st, 2019 and as per the "A 2/3 majority is required" for an RFC to pass, we can expect to see short arrow functions in an upcoming PHP release. Short Arrow Functions is currently targeted for the PHP 7.4 release.

"Anonymous functions in PHP can be quite verbose, even when they only perform a simple operation. Partly this is due to a large amount of syntactic boilerplate, and party due to the need to manually import used variables. This makes code using simple closures hard to read and understand. This RFC proposes a more concise syntax for this pattern."

quoted from the RFC introduction

The RFC proposed the following syntax for the short arrow functions: fn(parameter_list) => expr.

The RFC further provides an example of how it could be used:

Read more about it here:

Irfan Dahir

Irfan Dahir