几个类的PHP相同的命名空间

I wanted a clarification on the use of namespaces.

If I have two classes in the same namespace, like this:

<?php

namespace Test\Collection; 

class First{}

And:

<?php

namespace Test\Collection; 

class Second{}

In this case I can use them in this way?

use Test\Collection;

$first = new First();
$second = new Second();

Thanks.

you can use multiple classes of a namespace like below

use Test\Collection as Container;

$first = new Container\First();
$second = new Container\Second();

I think second solution from @Will may not work at some cases.

for your better understanding take a look at this explanation. Hope this helps

Not quite.

With your example, you'd need:

<?php

use Test\Collection\First;
use Test\Collection\Second;

$first = new First();
$second = new Second();

Or:

<?php

use Test\Collection;

$first = new Collection\First();
$second = new Collection\Second();

See the documentation for more information. This is known as "namespace importing or aliasing".