trailing-comma-function-args View as Markdown

Declined
Authors
Sara Golemon pollita@php.net
Date
2013-02-19
Version
1.0
Source
wiki.php.net/rfc/trailing-comma-function-args

Vote

Should the current optional trailing comma implementation be merged closed
Yes
15
No
20
35 voters
aharvey Yes 2013-03-14 17:04
andi No 2013-03-20 23:15
auroraeosrose Yes 2013-03-20 19:47
brianlmoon No 2013-03-14 17:21
danbeck No 2013-03-14 19:21
derick No 2013-03-14 11:31
dm No 2013-03-14 21:26
dmitry No 2013-03-14 21:47
fa No 2013-03-14 20:23
gwynne No 2013-03-14 18:59
hradtke No 2013-03-14 20:32
indeyets Yes 2013-03-15 11:12
ircmaxell Yes 2013-03-14 12:01
kalle No 2013-03-14 10:58
lbarnaud Yes 2013-03-14 10:04
levim No 2013-03-14 16:52
lstrojny No 2013-03-14 09:23
marco Yes 2013-03-14 17:01
mfonda Yes 2013-03-15 16:41
mgf No 2013-03-14 16:45
mike Yes 2013-03-14 09:50
nikic No 2013-03-14 14:11
patrickallaert Yes 2013-03-15 09:21
pierrick Yes 2013-03-14 19:30
pollita Yes 2013-03-14 08:32
ramsey Yes 2013-03-20 19:38
reeze No 2013-03-14 17:04
salathe No 2013-03-14 13:30
sascham78 No 2013-03-19 15:00
stas No 2013-03-14 20:15
treffynnon Yes 2013-03-20 15:53
tyrael Yes 2013-03-14 19:48
uw No 2013-03-14 12:14
wez Yes 2013-03-16 00:49
zeev No 2013-03-20 21:20

Discussions on the mailing list

[RFC] Allow trailing comma in function call argument lists
by Sara Golemon · 65 messages
rfc:trailing-comma-function-args
by Rasmus Schultz · 3 messages
[VOTE] Trailing comma
by Sara Golemon · 1 message

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:53 UTC

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.

Vote: Should the current optional trailing comma implementation be merged — Yes: 15 · No: 20 (closed)

Changelog

  • Expanded proposal to include declarations as well as arguments 2013-02-20 11:23 GMT