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 revision
Next 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 <pollita@php.net>
 +  * Status: Voting Open
 +  * First Published at: http://wiki.php.net/rfc/trailing-comma-function-args
  
 +===== Introduction =====
 +
 +PHP has long supported trailing commas in array declarations like so:
 +
 +  <?php
 +  $a = array(
 +         'Orange',
 +         'Apple',
 +         'Banana',
 +        );
 +
 +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(
 +          "sample.txt",
 +          "r+",
 +         );
 +
 +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://github.com/sgolemon/php-src/compare/master...trailing-comma
 +
 +HipHop version: https://github.com/facebook/hiphop-php/commit/c1b7da6a4c128af5ddfc75f515c205de9f417a1e
 +===== 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't actually help the VCS blame issue anyway
 +
 +  <?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.
 +
 +<doodle 
 +title="Should the current optional trailing comma implementation be merged" auth="pollita" voteType="single" closed="False">
 +   * Yes
 +   * No
 +</doodle>
 +
 +===== 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