Take the State of PHP 2026 Survey →

Allow trailing comma in parameter list View as Markdown

Implemented (PHP 8.0)
Authors
Nikita Popov nikic@php.net
Date
2020-03-26
Target
PHP 8.0
Implementation
https://github.com/php/php-src/pull/5306
Source
wiki.php.net/rfc/trailing_comma_in_parameter_list

Vote

Allow trailing comma in parameter lists? closed
Yes
58
No
1
59 voters
ajf Yes 2020-04-14 16:19
alcaeus Yes 2020-04-15 15:00
as Yes 2020-04-24 06:00
asgrim Yes 2020-04-14 10:28
ashnazg Yes 2020-04-15 12:57
beberlei Yes 2020-04-14 11:23
bmajdak No 2020-04-14 18:45
brzuchal Yes 2020-04-14 14:08
bwoebi Yes 2020-04-14 10:52
carusogabriel Yes 2020-04-14 13:06
cmb Yes 2020-04-14 11:18
colinodell Yes 2020-04-14 11:09
danack Yes 2020-04-14 10:23
daverandom Yes 2020-04-17 18:17
derick Yes 2020-04-14 10:18
duncan3dc Yes 2020-04-14 12:04
ekin Yes 2020-04-15 13:34
galvao Yes 2020-04-14 11:06
girgias Yes 2020-04-14 10:33
jasny Yes 2020-04-15 07:34
jbnahan Yes 2020-04-21 06:14
jhdxr Yes 2020-04-15 16:56
kalle Yes 2020-04-14 15:45
kelunik Yes 2020-04-19 20:14
kguest Yes 2020-04-21 08:01
klaussilveira Yes 2020-04-21 12:54
kocsismate Yes 2020-04-14 10:23
krakjoe Yes 2020-04-15 06:54
malukenho Yes 2020-04-23 07:50
marcio Yes 2020-04-23 17:05
mariano Yes 2020-04-14 11:22
mcmic Yes 2020-04-15 08:19
mfonda Yes 2020-04-14 16:28
mike Yes 2020-04-21 11:44
nicolasgrekas Yes 2020-04-14 11:04
nikic Yes 2020-04-14 10:17
ocramius Yes 2020-04-14 10:28
peehaa Yes 2020-04-17 16:30
petk Yes 2020-04-23 09:10
pmjones Yes 2020-04-14 13:32
pmmaga Yes 2020-04-17 13:02
pollita Yes 2020-04-20 12:57
ramsey Yes 2020-04-14 12:20
reywob Yes 2020-04-14 14:27
royopa Yes 2020-04-14 10:33
ruudboon Yes 2020-04-20 05:43
salathe Yes 2020-04-14 10:21
sammyk Yes 2020-04-18 18:29
sebastian Yes 2020-04-14 14:03
sergey Yes 2020-04-20 11:19
sirsnyder Yes 2020-04-14 12:15
stas Yes 2020-04-14 15:57
svpernova09 Yes 2020-04-14 12:57
tandre Yes 2020-04-14 14:44
tiffany Yes 2020-04-20 20:13
trowski Yes 2020-04-21 19:24
villfa Yes 2020-04-15 18:29
wyrihaximus Yes 2020-04-19 16:23
yunosh Yes 2020-04-15 07:23

Discussions on the mailing list

[RFC] Allow trailing comma in parameter lists
by Nikita Popov · 14 messages
[VOTE] Allow trailing comma in parameter lists
by Nikita Popov · 2 messages
Permitting trailing commas in closure use() declarations
by tyson andre · 3 messages

RFC text

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

Introduction

This RFC proposes to allow an optional trailing comma in parameter lists. This is already supported for argument lists.

Consider the constructor of the League\Uri\Uri class:

class Uri {
    private function __construct(
        ?string $scheme,
        ?string $user,
        ?string $pass,
        ?string $host,
        ?int $port,
        string $path,
        ?string $query,
        ?string $fragment // <-- ARGH!
    ) {
        ...
    }
}

This constructor has too many parameters to place all of them on one line, at least under conventional coding standards. In such cases PSR-12 recommends to use the formatting above instead.

Unfortunately, it is currently not possible to place a trailing comma in the parameter list. This breaks uniformity, and results in larger diffs when a new optional parameter is added. Additionally, it is inconsistent with call-sites, which do allow a trailing comma:

new Uri(
    $scheme,
    $user,
    $pass,
    $host,
    $port,
    $path,
    $query,
    $fragment, // <-- Huh, this is allowed!
);

At this point, I'm used to always adding a trailing comma to multi-line lists, regardless of what kind of element they contain. I write the comma by default, and then have to go back to remove it upon receiving an error. We should avoid having this kind of arbitrary restriction.

Proposal

Allow a single optional trailing comma in parameter lists. This includes parameter lists for functions, methods and closures.

Prior Art

Allow a trailing comma in function calls added support for trailing commas in calls.

Trailing Commas In List Syntax was a previous proposal to support optional trailing commas in all list-like structures.

Nothing has substantially changed since those RFCs in technical terms, but I think the aforementioned style for breaking up large parameter lists has become more accepted in the meantime, and features like Constructor Property Promotion are going to increase its use further.

Backward Incompatible Changes

None.

Vote

Voting opened 2020-04-14 and closes 2020-04-28.

Vote: Allow trailing comma in parameter lists? — Yes: 58 · No: 1 (closed)