rfc:list-syntax-trailing-commas
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:list-syntax-trailing-commas [2015/11/03 19:01] – created sammyk | rfc:list-syntax-trailing-commas [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
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 |
* Author: Sammy Kaye Powers, me@sammyk.me | * Author: Sammy Kaye Powers, me@sammyk.me | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
===== 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: | Per the feedback on the internals list, this RFC broadens the scope of the [[rfc: | ||
Line 22: | Line 24: | ||
This makes for clean diffs and easy appending of new values in user-land. | This makes for clean diffs and easy appending of new values in user-land. | ||
- | Unfortunately, | + | Unfortunately, |
=== Raises a parse error === | === Raises a parse error === | ||
<code php> | <code php> | ||
- | // Parse error | + | <?php |
- | myFunc( | + | use Foo\Bar\{ |
- | | + | |
- | | + | |
- | | + | |
+ | }; | ||
</ | </ | ||
Line 38: | Line 41: | ||
- Offer a consistent API and match the existing array functionality. | - Offer a consistent API and match the existing array functionality. | ||
- | - Make it easy to append new elements in user-land. | + | - Make it easy to append new elements |
- | - Have cleaner diffs (so only one line shows up as being modified when appending | + | - Have cleaner diffs (so only one line shows up as being modified when appending |
- | - It makes code reviews a tiny bit faster and for really large codebases, that time adds up. ([[https:// | + | - It makes code reviews a tiny bit faster and for really large codebases, that time adds up. ([[https:// |
- | The list syntaxes that would be affected are: | + | The following lists would allow trailing commas: |
- Grouped namepaces | - Grouped namepaces | ||
Line 49: | 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:// | [[https:// | ||
Line 57: | Line 61: | ||
// Grouped namepaces | // Grouped namepaces | ||
use Foo\Bar\{ Foo, Bar, Baz, }; | use Foo\Bar\{ Foo, Bar, Baz, }; | ||
+ | |||
// Arrays (already possible) | // Arrays (already possible) | ||
$array = [1, 2, 3,]; | $array = [1, 2, 3,]; | ||
+ | |||
// Function/ | // Function/ | ||
fooCall($arg1, | fooCall($arg1, | ||
+ | |||
class Foo implements | class Foo implements | ||
// Interface implementations on a class | // Interface implementations on a class | ||
Line 86: | Line 93: | ||
$c = ' | $c = ' | ||
; | ; | ||
- | | ||
private | private | ||
$blah, | $blah, | ||
Line 96: | Line 102: | ||
} | } | ||
} | } | ||
+ | |||
+ | // Inheriting variables from the parent scope in anonymous functions | ||
+ | $foo = function ($bar) use ( | ||
+ | $a, | ||
+ | $b, | ||
+ | $c, | ||
+ | ) { | ||
+ | // . . . | ||
+ | }; | ||
</ | </ | ||
Line 116: | Line 131: | ||
==== Why allocate resources to make this happen ==== | ==== Why allocate resources to make this happen ==== | ||
- | The actual implementation for adding tailing commas to function arguments/ | + | The actual implementation for adding tailing commas to function arguments/ |
- | ==== You could use leading commas ==== | + | ==== You could just use leading commas ==== |
<code php> | <code php> | ||
Line 133: | Line 148: | ||
==== The arguments for & against are weak ==== | ==== The arguments for & against are weak ==== | ||
- | TL;DR: | + | **TL;DR:** |
- | For: It's handy. (And the reasons detailed above). | + | |
- | Against: It's ugly. There are only minor gains. | + | * **For it:** It's handy. (And the reasons detailed above). |
+ | * **Against:** It's ugly. There are only minor gains. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 143: | 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 | + | Each trailing comma list syntax |
- | - Function/ | + | |
- | | + | ==== Function/ |
- | | + | |
- | | + | <code php> |
- | | + | // Function/ |
+ | fooCall( | ||
+ | $arg1, | ||
+ | $arg2, | ||
+ | $arg3, | ||
+ | ); | ||
+ | |||
+ | // Function/ | ||
+ | function something( | ||
+ | FooBarBazInterface $in, | ||
+ | FooBarBazInterface $out, | ||
+ | ) : bool { | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ==== Grouped namepaces | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | use Foo\Bar\{ | ||
+ | Foo, | ||
+ | Bar, | ||
+ | Baz, | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ==== Interface implementations on a class ==== | ||
+ | |||
+ | <code php> | ||
+ | class Foo implements | ||
+ | FooInterface, | ||
+ | BarInterface, | ||
+ | BazInterface, | ||
+ | { | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ==== Trait implementations on a class ==== | ||
+ | |||
+ | <code php> | ||
+ | class Foo | ||
+ | { | ||
+ | use | ||
+ | FooTrait, | ||
+ | BarTrait, | ||
+ | BazTrait, | ||
+ | ; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ==== Class member lists ==== | ||
+ | |||
+ | <code php> | ||
+ | class Foo | ||
+ | { | ||
+ | const | ||
+ | A = 1010, | ||
+ | B = 1021, | ||
+ | C = 1032, | ||
+ | D = 1043, | ||
+ | ; | ||
+ | protected | ||
+ | $a = ' | ||
+ | $b = ' | ||
+ | $c = ' | ||
+ | ; | ||
+ | private | ||
+ | $blah, | ||
+ | ; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ==== Inheriting variables from the parent scope in anonymous functions ==== | ||
+ | |||
+ | <code php> | ||
+ | $foo = function ($bar) use ( | ||
+ | $a, | ||
+ | $b, | ||
+ | $c, | ||
+ | ) { | ||
+ | // . . . | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
The [[https:// | The [[https:// |
rfc/list-syntax-trailing-commas.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1