Skip to content

Commit 5601f11

Browse files
committed
Update Short Closures spec to remove space after fn keyword
Per the accepted [Arrow Functions RFC](https://wiki.php.net/rfc/arrow_functions_v2) and [per its author](https://www.reddit.com/r/PHP/comments/fctb18/comment/fjd9u6a/), short closures were intended to be written without a space after the `fn` keyword. This is also the default formatting enforced by PhpStorm. PHP-CS-Fixer was an outlier which incorrectly enforced spacing after the `fn` keyword using the same setting as for the `function` keyword. This was a bug and has been corrected with the addition of a separate `closure_fn_spacing` setting (though this setting still defaults to `one` for backwards compatibility - the intention was to [change it to enforce no space](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/b577444c38b61f2fdc32cd0a4685bd595be391b7/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php#L235) in the next major 4.0 version). The primary goal of arrow functions is to avoid the verbosity of anonymous functions, so requiring a space after the `fn` keyword is a step backwards from this, and also doesn't align with general usage promoted by PhpStorm as well as the accepted PHP RFC and documentation. The section on Short Closures was not added until the 17th of July by #17, which was after the 1.0.0 spec was approved/released on June 9, so I'm hoping it's not too late to correct it.
1 parent b49fd56 commit 5601f11

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

spec.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ $foo->bar(
11481148
Short closures, also known as arrow functions, MUST follow the same guidelines
11491149
and principles as long closures above, with the following additions.
11501150

1151-
The `fn` keyword MUST be preceded and succeeded by a space.
1151+
The `fn` keyword MUST be preceded by a space, and MUST NOT be succeeded by a space.
11521152

11531153
The `=>` symbol MUST be preceded and succeeded by a space.
11541154

@@ -1161,12 +1161,12 @@ The following examples show proper common usage of short closures.
11611161

11621162
```php
11631163

1164-
$func = fn (int $x, int $y): int => $x + $y;
1164+
$func = fn(int $x, int $y): int => $x + $y;
11651165

1166-
$func = fn (int $x, int $y): int
1166+
$func = fn(int $x, int $y): int
11671167
=> $x + $y;
11681168

1169-
$func = fn (
1169+
$func = fn(
11701170
int $x,
11711171
int $y,
11721172
): int

0 commit comments

Comments
 (0)