PHP 7.3: Allow trailing comma in function and method calls

Version7.3
TypeChange

This is a simple change, which suggests allowing trailing commas in function and method calls. This does not affect declarations.

For example, the following syntax would be allowed:

// regular functions.  
foo('bar', 'baz',); // Notice the trailing comma after 'baz'.

In pre-PHP-7.3, the snippet above throws an error PHP Parse error: syntax error, unexpected ')' in .. on line ..

You cannot use more than one commas at the end or use commas to skip arguments - the advantage of this change is mainly for those functions with variadic parameters. This change also makes the array syntax (which allows trailing commas already) consistent.

Note that you cannot use this in function/method declarations; this is wrong:

function foo($bar, $baz, ) { // Not allowed.
}

Backwards compatibility impact

None - Your existing code will continue to work. If you have any function calls that accept variadic parameters and believe that you could make diffs cleaner with this, I'd suggest you go ahead and add trailing commas to the calls. If you put a trailing comma for every function call, you are clearly overdoing it.

RFC Externals.io discussion Implementation