rfc:trailing-comma-function-args
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | rfc:trailing-comma-function-args [2013/03/14 08:44] – Mention which version this is targeting. pollita | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Request for Comments: Trailing comma function args ====== | ||
+ | * Version: 1.0 | ||
+ | * Date: 2013-02-19 | ||
+ | * Author: Sara Golemon < | ||
+ | * Status: Voting Open | ||
+ | * First Published at: http:// | ||
+ | ===== Introduction ===== | ||
+ | |||
+ | PHP has long supported trailing commas in array declarations like so: | ||
+ | |||
+ | <?php | ||
+ | $a = array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | |||
+ | This is useful for VCS (cvs, svn, git, hg, etc...) since individual lines in the list may be modified, added, or removed without having to touch unrelated lines which happen to be at the end of the list. | ||
+ | |||
+ | Function call arguments do not share this trait. | ||
+ | |||
+ | <?php | ||
+ | // This is an error | ||
+ | $fp = fopen( | ||
+ | " | ||
+ | " | ||
+ | ); | ||
+ | |||
+ | Which means that adding additional parameters to the call forces touching both the new line and the prior one, which is bad for VCS history. | ||
+ | |||
+ | Similarly, function declarations have the same inconsistency with array() and list(). | ||
+ | |||
+ | <?php | ||
+ | // Invalid currently | ||
+ | function foo( | ||
+ | $bar, | ||
+ | ) { | ||
+ | /* ... */ | ||
+ | } | ||
+ | |||
+ | This RFC proposes to allow trailing commas in function and method call argument lists and function argument declarations. | ||
+ | |||
+ | ===== The patch ===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | HipHop version: https:// | ||
+ | ===== What's left out on purpose ===== | ||
+ | |||
+ | Bonus comma in the middle of a void argument list | ||
+ | * It implies two ignored args, rather than one | ||
+ | * It doesn' | ||
+ | |||
+ | <?php | ||
+ | phpinfo( | ||
+ | , | ||
+ | ); | ||
+ | |||
+ | Trailing comma in yield() expression | ||
+ | * yield only takes one value (or key=>val expression) | ||
+ | * yield is not really a function call, even if it looks like one | ||
+ | |||
+ | <?php | ||
+ | function mygen() { | ||
+ | yield( | ||
+ | 123, | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | ===== Vote ===== | ||
+ | |||
+ | Note: Consideration for 5.6 inclusion, not 5.5. | ||
+ | |||
+ | < | ||
+ | title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * Expanded proposal to include declarations as well as arguments 2013-02-20 11:23 GMT |
rfc/trailing-comma-function-args.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1