# Group Use Declarations

> Section in “New and Extended Functionality › Language Features” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/language-features/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:

``` php
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.

``` php
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:

``` php
namespace php7\explained;

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

---

Previous: [Assertions](https://php7explained.com/new-and-extended-functionality/language-features/assertions/index.html.md) | Next: [Countable Interface and Internal Classes](https://php7explained.com/new-and-extended-functionality/language-features/countable-interface-and-internal-classes/index.html.md)
