Skip to content

Commit

Permalink
Add a section on short-lambdas.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell committed Jun 1, 2022
1 parent b5cac84 commit aaade6f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aaade6f

Please sign in to comment.