Problem/Motivation

PHP arrow functions are a useful shorthand for inline anonymous functions, e.g. when used as a custom callback to a PHP function such as array_filter().

Several questions arise that I can see:

1. Do we need standards on when to use these vs. normal anonymous functions?

2. Typically, they are written to be fairly compact. Do we need to suspend the coding standard for variable names not using abbreviations, in particular the function parameters?

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

joachim created an issue. See original summary.

eric_a’s picture

eric_a’s picture

eric_a’s picture

From https://www.php-fig.org/per/coding-style/#71-short-closures:

Short closures, also known as arrow functions, MUST follow the same guidelines and principles as long closures above, with the following additions.

The fn keyword MUST NOT be succeeded by a space.

drunken monkey’s picture

@eric_a: Seems we’re currently pretty undecided on that, so seems like a good thing for which to put a standard in place. And probably to use the one from FIG, then. (Even though I personally prefer it with the space.)

$ git ls | grep '\.php$' | xargs grep -hPo '\bfn ?\(' | sort | uniq -c
    108 fn (
     85 fn(
joachim’s picture

@eric_a yes, but what's their reasoning for the difference?