From f2c68cfbee88fe7991ae4be3715426798b25580c Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 1 Jun 2022 17:05:11 -0500 Subject: [PATCH] Add a section on short-lambdas. --- spec.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec.md b/spec.md index 66dbad4..102c7ac 100644 --- a/spec.md +++ b/spec.md @@ -1047,6 +1047,36 @@ $foo->bar( ); ``` +### 7.1 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 be preceded and succeeded by a space. + +The `=>` symbol MUST be preceded and succeeded by a space. + +The semicolon at the end of the expression MUST NOT be preceded by a space. + +The expression portion MAY be split to a subsequent line. If so, the `=>` MUST be included +on the second line, and MUST be indented once. + +The following examples show proper common usage of short closures. + +```php + +$func = fn (int $x, int $y): int => $x + $y; + +$func = fn (int $x, int $y): int + => $x + $y; + +$func = fn ( + int $x, + int $y +): int + => $x + $y; +``` + ## 8. Anonymous Classes Anonymous Classes MUST follow the same guidelines and principles as closures