Group use declarations
Classes, functions, and constants, which are in the same namespace, can now imported in a single use
statement. Previously, multiple use
statements were required for that. Here is an example to understand it better:
<?php // use statement in Pre-PHP7 code use abc\namespace\ClassA; use abc\namespace\ClassB; use abc\namespace\ClassC as C; use function abc\namespace\funcA; use function abc\namespace\funcB; use function abc\namespace\funcC; use const abc\namespace\ConstA; use const abc\namespace\ConstB; use const abc\namespace\ConstC; // PHP 7+ code use abc\namespace\{ClassA, ClassB, ClassC as C}; use function abc\namespace\{funcA, funcB, funcC}; use const abc\namespace\{ConstA, ConstB, ConstC};
As you can see from this example, how convenient the group use statement is, it is clearly visible. Curly braces with comma separated values are used to group values such as {classA, classB, classC as C}
, resulting in the grouped use
statement, instead of separately using...