dsfjk44656 2015-12-30 03:13
浏览 262
已采纳

几个类的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.

  • 写回答

2条回答 默认 最新

  • doupi4649 2015-12-30 06:36
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部