Last updated on December 13, 2015
PHP 7 is improved current PHP namespace implementation by introducing the concept of Group Use. This is the one of the coolest improvement to namespaces in PHP7. Group use
Declarations are more readable and makes it easier to import classes, constants and functions in a concise way.
Group use
declarations give the ability to import multiple structures from a common namespace and cuts a good level of verbosity in most cases. Group use
declarations makes it easier to identify that multiple imported entities belong to the same module.
// Pre PHP 7 code use some\namespace\ClassA; use some\namespace\ClassB; use some\namespace\ClassC as C; use function some\namespace\fn_a; use function some\namespace\fn_b; use function some\namespace\fn_c; use const some\namespace\ConstA; use const some\namespace\ConstB; use const some\namespace\ConstC; // PHP 7+ code use some\namespace\{ClassA, ClassB, ClassC as C}; use function some\namespace\{fn_a, fn_b, fn_c}; use const some\namespace\{ConstA, ConstB, ConstC};