【发布时间】:2014-05-31 11:52:48
【问题描述】:
其实我的问题很简单。在 PHP 中,我可以在将使用 require 或 include 加载的文件中定义名称空间。 示例:
index.php 的内容
namespace test;
require('example.php');
die(__NAMESPACE__);
example.php 的内容
namespace example;
echo "hello world";
如果您执行此代码,输出将为“test”,因为如果您包含具有另一个名称空间的文件,则名称空间不会改变。
但是你能告诉我为什么吗?我怎么能想象解析器? 它可能看起来像:
namespace test{}
namespace example{}
// and here it goes on with test, but why I didn´t said namespace test
namespace test{}
【问题讨论】:
标签: php namespaces