donglan7594 2010-02-09 15:08
浏览 27
已采纳

如何在PHP中实现嵌套命名空间?

use level1\level2\level3;

Can someone explain with a simple demo ?

  • 写回答

1条回答 默认 最新

  • dongtang3155 2010-02-09 15:17
    关注

    To clear up any confusion regarding different syntax use, namespaces support only two syntaxes, either bracketed or simple-combination both will work. I suggest if you use one over the other, be consistent.

    <?php
    namespace my\stuff
    ested {  // <- bracketed syntax
     class foo {}
    }
    ?>
    

    It creates a class foo inside of the nested namespace with bracketed syntax ({}), it is equivalent to

    <?php
    namespace my\stuff {  // bracketed syntax but with a nested look
      namespace nested {
         class foo {}
      }
    }
    ?>
    

    You can also use nested namespaces with simple-combination syntax (;)

    <?php
    namespace mine;
    use ultra\long
    s
    ame;  // <- simple-combination syntax
    
    $a = name\CONSTANT;
    name\func();
    ?>
    

    PHP: FAQ: things you need to know about namespaces

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu服务器配置dns域名后无法访问其他域名
  • ¥50 本人复制了一个关于股票指标的代码,但是运行失败,有没有人帮我解决一下
  • ¥50 用matlab和numeca做透平机械流体力学和热力学模拟 价格可议
  • ¥15 Unity3D WebView
  • ¥20 论文AlphaTensor复现(有偿)
  • ¥15 (有偿)在ANSYS中 .anf文件
  • ¥45 关于#芯片#的问题:组合逻辑电路设计
  • ¥15 基与机器学习和时间序列分析预测养老服务需求趋势
  • ¥100 求连续两帧图像在水平和垂直上偏移
  • ¥15 Verilog hdl密码锁设计