Closed
Description
These have similar properties to closures, except:
- There is a single expression instead of a function body
- There is no use clause, it's implicit
More details can be found in https://wiki.php.net/rfc/arrow_functions_v2
Arrow functions have lowest precedence. This means that the expression to the right of => will be consumed as far as possible:
Examples:
fn(array $x) => $x;
fn(): int => $x;
fn($x = 42) => yield $x;
fn(&$x) => $x;
fn&($x) => $x;
fn($x, ...$rest) => $rest;
static fn() => 1;
Ideas on how this would be represented:
Create a new ArrowFunctionCreationExpression with staticModifier, FunctionHeader, FunctionReturnType, arrowToken, and resultExpression: Token|Node (instead of FunctionBody). There would be no FunctionUseClause.
It would have these properties in this order (when the ast is valid):
- staticModifier: Token|null
- functionKeyword: Token (to reuse FunctionName, but
fn
instead offunction
) - byRefToken: Token|null
- openParen: Token
- parameters: DelimitedList\ParameterDeclarationList
- closeParen: Token
- colonToken: Token|null
- questionToken: Token|null
- returnType: Token|qualifiedName
- arrowToken: Token (
=>
) - resultExpression: Token|Node
Metadata
Metadata
Assignees
Labels
No labels