rfc:auto-capture-closure

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:auto-capture-closure [2022/07/01 09:57] lbarnaudrfc:auto-capture-closure [2022/07/16 09:43] (current) lbarnaud
Line 5: Line 5:
   * Author: Larry Garfield (larry@garfieldtech.com)   * Author: Larry Garfield (larry@garfieldtech.com)
   * Author: Arnaud Le Blanc (arnaud.lb@gmail.com)   * Author: Arnaud Le Blanc (arnaud.lb@gmail.com)
-  * Status: In Discussion+  * Status: Declined
   * First Published at: http://wiki.php.net/rfc/auto-capture-closure   * First Published at: http://wiki.php.net/rfc/auto-capture-closure
  
Line 282: Line 282:
   * In all other situations in which a variable is used, it is assumed that it is read   * In all other situations in which a variable is used, it is assumed that it is read
  
-This optimization is not applied to Arrow Functions.+This optimization is not applied to Arrow Functions because variable bindings are unusual in these functions.
  
 ==== Observable effects of capture ==== ==== Observable effects of capture ====
Line 385: Line 385:
 Existing function syntaxes continues to work precisely as they do now.  Only new combinations are possible. Existing function syntaxes continues to work precisely as they do now.  Only new combinations are possible.
  
-===== Unaffected PHP Functionality =====+===== Future Scope =====
  
 These are some possible future extensions, but the authors don't necessarily endorse them. These are some possible future extensions, but the authors don't necessarily endorse them.
Line 394: Line 394:
  
 <code php> <code php>
-$fn = fn() use($a, &$b) {+$fn = fn () use ($a, &$b) {
 }; };
 </code> </code>
  
-One benefit of this syntax is that it allows to selectively capture some variables by-reference.+One anticipated use-case is to selectively capture some variables by-reference.
  
-This is not included in this RFC because it appeared to create confusion. +There are at least two possible variations of this extensionIn one of them, the use list is merged with auto-capture, so that explicit uses and auto-capture can coexist on the same function. In another the use list disables auto-capture on the function.
- +
-==== Opt-in auto-capture on Anonymous Functions ==== +
- +
-It would be possible to add opt-in auto-capture to Anonymous Functions:  +
- +
-<code php> +
-$f = function() use (*) { +
-}; +
-</code>+
  
-This is not included in this RFC because Short Closures already achieve this without the extra syntax.+This RFC initially proposed the first possibility. This is not included in the current version because this appeared to create confusion.
  
 ==== Optimize Arrow Functions ==== ==== Optimize Arrow Functions ====
  
-This RFC proposes an optimized auto-capture. It would be possible to apply this optimization to Arrow Functions as well. This would be a breaking change in some rare cases.+This RFC proposes an optimized auto-capture. It would be possible to apply this optimization to Arrow Functions as well, but this would be a breaking change in some rare cases.
  
 This is not included in this RFC because most Arrow Functions would not benefit from this. This is not included in this RFC because most Arrow Functions would not benefit from this.
  
-===== Proposed Voting Choices =====+===== Vote =====
  
-This is a simple Yes/No vote, requiring 2/3 to pass.+This is a simple Yes/No vote, requiring 2/3 to pass.  Vote ends on 15 July 2022.
  
  
rfc/auto-capture-closure.1656669470.txt.gz · Last modified: 2022/07/01 09:57 by lbarnaud