Skip to content

Add a section on short-lambdas #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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