This is an old revision of the document!

Request for Comments: Trailing comma function args


PHP has long supported trailing commas in array declarations like so:

$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.

// 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().

// Invalid currently
function foo(
           ) {
  /* ... */

This RFC proposes to allow trailing commas in function and method call argument lists and function argument declarations.

The patch

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

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
function mygen() {


  • Expanded proposal to include declarations as well as arguments 2013-02-20 11:23 GMT
rfc/trailing-comma-function-args.1361444860.txt.gz · Last modified: 2013/02/21 12:07 by pollita