# RFC: trailing-comma-function-args

- Status: Declined
- Authors: Sara Golemon pollita@php.net
- Date: 2013-02-19
- Version: 1.0
- Original: https://wiki.php.net/rfc/trailing-comma-function-args
- Page: https://externals.io/rfc/trailing-comma-function-args
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### Should the current optional trailing comma implementation be merged (closed)

Yes: 15 · No: 20

Voters: aharvey (Yes), andi (No), auroraeosrose (Yes), brianlmoon (No), danbeck (No), derick (No), dm (No), dmitry (No), fa (No), gwynne (No), hradtke (No), indeyets (Yes), ircmaxell (Yes), kalle (No), lbarnaud (Yes), levim (No), lstrojny (No), marco (Yes), mfonda (Yes), mgf (No), mike (Yes), nikic (No), patrickallaert (Yes), pierrick (Yes), pollita (Yes), ramsey (Yes), reeze (No), salathe (No), sascham78 (No), stas (No), treffynnon (Yes), tyrael (Yes), uw (No), wez (Yes), zeev (No)

## Discussions on the mailing list

- [\[RFC\] Allow trailing comma in function call argument lists](https://externals.io/message/65931.md) — started on 2013-02-19, 65 messages
- [rfc:trailing-comma-function-args](https://externals.io/message/66164.md) — started on 2013-02-22, 3 messages
- [\[VOTE\] Trailing comma](https://externals.io/message/66620.md) — started on 2013-03-14, 1 messages

---

## 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=&gt;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
