rfc:auto-capture-lambda
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:auto-capture-lambda [2021/03/24 15:31] – Updates from Nuno crell | rfc:auto-capture-lambda [2021/03/24 15:54] – crell | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== PHP RFC: Auto-capturing multi-line lambdas | + | ====== PHP RFC: Auto-capturing multi-statement closures |
* Version: 0.9 | * Version: 0.9 | ||
* Date: 2021-03-22 | * Date: 2021-03-22 | ||
Line 8: | Line 8: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Lambdas | + | Closures (also known as lambdas or anonymous functions), |
<code php> | <code php> | ||
+ | // As of 8.0: | ||
+ | |||
$y = 1; | $y = 1; | ||
Line 72: | Line 74: | ||
* named function, auto-capture, | * named function, auto-capture, | ||
* named function, auto-capture, | * named function, auto-capture, | ||
- | * anonymous function, manual-capture, | + | * anonymous function, manual-capture, |
- | ==== Auto-capture multi-statement | + | ==== Auto-capture multi-statement |
Specifically, | Specifically, | ||
Line 95: | Line 97: | ||
* The '' | * The '' | ||
* The '' | * The '' | ||
- | * A function with a name is declared globally at compile time. A function without a name is declared locally as a lambda | + | * A function with a name is declared globally at compile time. A function without a name is declared locally as a closure |
These rules are easily recognizable and learnable by developers. | These rules are easily recognizable and learnable by developers. | ||
Line 103: | Line 105: | ||
As methods cannot be anonymous, there are no impacts on methods from this RFC. The short-functions RFC does address methods, and does so in a way that is completely consistent with the syntactic rules defined above. | As methods cannot be anonymous, there are no impacts on methods from this RFC. The short-functions RFC does address methods, and does so in a way that is completely consistent with the syntactic rules defined above. | ||
- | ==== What about long-lambdas? ==== | + | ==== What about long-closures? ==== |
- | The existing multi-line | + | The existing multi-line |
* When it is desirable to capture variables explicitly, such as to avoid name collision. | * When it is desirable to capture variables explicitly, such as to avoid name collision. |
rfc/auto-capture-lambda.txt · Last modified: 2021/03/24 15:58 by crell