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 (aharvey)  
andi (andi)  
auroraeosrose (auroraeosrose)  
brianlmoon (brianlmoon)  
danbeck (danbeck)  
derick (derick)  
dm (dm)  
dmitry (dmitry)  
fa (fa)  
gwynne (gwynne)  
hradtke (hradtke)  
indeyets (indeyets)  
ircmaxell (ircmaxell)  
kalle (kalle)  
lbarnaud (lbarnaud)  
levim (levim)  
lstrojny (lstrojny)  
marco (marco)  
mfonda (mfonda)  
mgf (mgf)  
mike (mike)  
nikic (nikic)  
patrickallaert (patrickallaert)  
pierrick (pierrick)  
pollita (pollita)  
ramsey (ramsey)  
reeze (reeze)  
salathe (salathe)  
sascham78 (sascham78)  
stas (stas)  
treffynnon (treffynnon)  
tyrael (tyrael)  
uw (uw)  
wez (wez)  
zeev (zeev)  
Final result: 15 20
This poll has been closed.

Changelog