©
이 문서에서는 PHP 중국어 웹사이트 매뉴얼 풀어 주다
(PHP 5 >= 5.3.0)
与目录和文件的关系很象,PHP 命名空间也允许指定层次化的命名空间的名称。因此,命名空间的名字可以使用分层次的方式定义:
Example #1 声明分层次的单个命名空间
<?php
namespace MyProject \ Sub \ Level ;
const CONNECT_OK = 1 ;
class Connection { }
function connect () { }
?>
[#1] do dot not dot reply at foxmail dot com [2014-09-24 03:46:00]
treat sub-namespaces as different namespace
a.php:
<?php namespace ABC;
const '__DOMAIN__' = 'example.com';
?>
b.php
<?php namespace ABC\SUBLEVEL;
require 'a.php';
echo __DOMAIN__; //Notice: Use of undefined constant __DOMAIN__
[#2] steve dot pye at gmail dot com [2014-09-16 18:57:47]
Wait a minute. So the document says to declare it like:
namespace Something\SomethingElse;
and you're saying "never do that"? what the what?
[#3] leaksin [ at ] gmail [ dot ] com [2013-07-30 14:58:57]
Never use slashes and dot in namespace declaration.
wrong formats:
<?php
namespace first\second.w;
?>
<?php
namespace first/second;
?>