What’s new in PHP 7.2

Trailing comma for any lists

wiki: https://wiki.php.net/rfc/list-syntax-trailing-commas

In the following lists trailing commas are allowed:

  • Grouped namespaces.
  • Function/method arguments (declarations and calls).
  • Interface implementations in a class.
  • Trait implementations in a class.
  • Lists of class members.
  • Inheriting variables from the parent scope in anonymous functions.
// Arrays (already possible)
$array = [1, 2, 3,];

// Grouped namepaces
use Foo\Bar\{ Foo, Bar, Baz, };

// Function/method arguments (call)
fooCall($arg1, $arg2, $arg3,);

class Foo implements
	// Interface implementations on a class
	FooInterface,
	BarInterface,
	BazInterface,
{
	// Trait implementations on a class
	use
		FooTrait,
		BarTrait,
		BazTrait,
	;

	// Class member lists
	const
		A = 1010,
		B = 1021,
		C = 1032,
		D = 1043,
	;
	protected
		$a = 'foo',
		$b = 'bar',
		$c = 'baz',
	;
	private
		$blah,
	;

	// Function/method arguments (declaration)
	function something(FooBarBazInterface $in, FooBarBazInterface $out,) : bool
	{
	}
}

// Inheriting variables from the parent scope in anonymous functions
$foo = function ( $bar ) use (
	$a,
	$b,
	$c,
) {
	// . . .
};