Group Use Declarations

The introduction of namespaces into PHP saved us from having countless underscores in class names. It also brought us the option to import collaborating classes from other namespaces by means of the use keyword:

namespace php7\explained;

use php7\example\ns\classA;
use php7\example\ns\classB;
use php7\example\ns\classC as Renamed;

Of course, that is quite verbose and was considered potentially too verbose. So to avoid repeating the common prefix of the namespaces over and over again, an alternative syntax has been introduced in PHP 7 to address this.

namespace php7\explained;

use php7\example\ns {
    classA,
    classB,
    classC as Renamed
};

This feature has been named group use declaration. While syntactically possible, the nesting of group declarations is not supported.

The syntax for group use declarations allows for trailing commas as of PHP 7.2. The following is now valid PHP code:

namespace php7\explained;

use php7\example\ns {
    classA,
    classB,
};