Table of Contents

Request for Comments: 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

<?php
phpinfo(
    ,
    );

Trailing comma in yield() expression

<?php
function mygen() {
  yield(
    123,
    );
}

Vote

Note: Consideration for 5.6 inclusion, not 5.5.

Should the current optional trailing comma implementation be merged
Real name Yes No
aharvey  
andi  
auroraeosrose  
brianlmoon  
danbeck  
derick  
dm  
dmitry  
fa  
gwynne  
hradtke  
indeyets  
ircmaxell  
kalle  
lbarnaud  
levim  
lstrojny  
marco  
mfonda  
mgf  
mike  
nikic  
patrickallaert  
pierrick  
pollita  
ramsey  
reeze  
salathe  
sascham78  
stas  
treffynnon  
tyrael  
uw  
wez  
zeev  
Final result: 15 20
This poll has been closed.

Changelog