rfc:list-syntax-trailing-commas

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
Last revisionBoth sides next revision
rfc:list-syntax-trailing-commas [2015/11/03 19:11] – type-o's sammykrfc:list-syntax-trailing-commas [2017/05/01 10:22] nikic
Line 1: Line 1:
 ====== PHP RFC: Trailing Commas In List Syntax ====== ====== PHP RFC: Trailing Commas In List Syntax ======
   * Version: 0.1   * Version: 0.1
-  * Date: 2015-11-03+  * Date: 2015-11-03 (discussion); 2017-01-27 (voting)
   * Author: Sammy Kaye Powers, me@sammyk.me   * Author: Sammy Kaye Powers, me@sammyk.me
-  * Status: Draft+  * Status: Implemented in PHP 7.2 (Grouped namepaces only)
   * First Published at: https://wiki.php.net/rfc/revisit-trailing-comma-function-args, https://wiki.php.net/rfc/trailing-comma-function-args   * First Published at: https://wiki.php.net/rfc/revisit-trailing-comma-function-args, https://wiki.php.net/rfc/trailing-comma-function-args
  
 ===== Introduction ===== ===== Introduction =====
 +
 +This RFC proposes allowing trailing commas for all list syntax.
  
 Per the feedback on the internals list, this RFC broadens the scope of the [[rfc:revisit-trailing-comma-function-args|original RFC to allow trailing commas in function arguments]] to all list syntax. Per the feedback on the internals list, this RFC broadens the scope of the [[rfc:revisit-trailing-comma-function-args|original RFC to allow trailing commas in function arguments]] to all list syntax.
Line 26: Line 28:
 === Raises a parse error === === Raises a parse error ===
 <code php> <code php>
-myFunc( +<?php 
-    $foo+use Foo\Bar\{ 
-    $bar+    Foo
-    );+    Bar
 +    Baz, 
 +};
 </code> </code>
  
Line 48: Line 52:
   - Trait implementations on a class   - Trait implementations on a class
   - Class member lists   - Class member lists
 +  - Inheriting variables from the parent scope in anonymous functions
  
 [[https://people.php.net/user.php?username=marcio|Marcio Almada]] posted a gist with [[https://gist.github.com/marcioAlmada/75f8f1d47da5dcac2e57|examples of trailing commas]] for the various lists (shown below): [[https://people.php.net/user.php?username=marcio|Marcio Almada]] posted a gist with [[https://gist.github.com/marcioAlmada/75f8f1d47da5dcac2e57|examples of trailing commas]] for the various lists (shown below):
Line 97: Line 102:
     }     }
 } }
 +
 +// Inheriting variables from the parent scope in anonymous functions
 +$foo = function ($bar) use (
 +    $a,
 +    $b,
 +    $c,
 +) {
 + // . . . 
 +};
 </code> </code>
  
Line 145: Line 159:
 ===== Proposed PHP Version ===== ===== Proposed PHP Version =====
  
-PHP 7.1+PHP 7.2
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
  
-Each trailing comma list syntax would get its own vote and would require a 2/3 majority to pass.+Each trailing comma list syntax has its own vote and requires a 2/3 majority to pass.
  
-  - Function/method arguments (declarations & calls) + 
-  Grouped namepaces +==== Function/method arguments (declarations & calls) ==== 
-  Interface implementations on a class + 
-  Trait implementations on a class +<code php> 
-  Class member lists+// Function/method arguments (call) 
 +fooCall( 
 +    $arg1, 
 +    $arg2, 
 +    $arg3, 
 +); 
 +     
 +// Function/method arguments (declaration) 
 +function something( 
 +    FooBarBazInterface $in, 
 +    FooBarBazInterface $out, 
 +) : bool { 
 +
 +</code> 
 + 
 +<doodle title="Allow trailing commas in function/method arguments (declarations and calls)" auth="SammyK" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +==== Grouped namepaces ==== 
 + 
 +<code php> 
 +<?php 
 +use Foo\Bar\{ 
 +    Foo, 
 +    Bar, 
 +    Baz, 
 +}; 
 +</code> 
 + 
 +<doodle title="Allow trailing commas in grouped namepaces" auth="SammyK" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +==== Interface implementations on a class ==== 
 + 
 +<code php> 
 +class Foo implements 
 +    FooInterface, 
 +    BarInterface, 
 +    BazInterface, 
 +
 +
 +</code> 
 + 
 +<doodle title="Allow trailing commas in interface implementations on a class" auth="SammyK" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +==== Trait implementations on a class ==== 
 + 
 +<code php> 
 +class Foo 
 +
 +    use 
 +        FooTrait, 
 +        BarTrait, 
 +        BazTrait, 
 +    ; 
 +
 +</code> 
 + 
 +<doodle title="Allow trailing commas in trait implementations on a class" auth="SammyK" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +==== Class member lists ==== 
 + 
 +<code php> 
 +class Foo 
 +
 +    const 
 +        A = 1010, 
 +        B = 1021, 
 +        C = 1032, 
 +        D = 1043, 
 +    ; 
 +    protected 
 +        $a = 'foo', 
 +        $b = 'bar', 
 +        $c = 'baz', 
 +    ; 
 +    private 
 +        $blah, 
 +    ; 
 +
 +</code> 
 + 
 +<doodle title="Allow trailing commas in class member lists" auth="SammyK" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +==== Inheriting variables from the parent scope in anonymous functions ==== 
 + 
 +<code php> 
 +$foo = function ($bar) use ( 
 +    $a, 
 +    $b, 
 +    $c, 
 +) { 
 + // . . .  
 +}; 
 +</code> 
 + 
 +<doodle title="Allow trailing commas in use lists for anonymous functions" auth="SammyK" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
  
 The [[https://github.com/sgolemon/php-src/compare/master...trailing-comma|original patch by Sara Golemon]]. The [[https://github.com/sgolemon/php-src/compare/master...trailing-comma|original patch by Sara Golemon]].
rfc/list-syntax-trailing-commas.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1