That's the expected behavior, you have to declare the namespace at the top of the file to "extend" it.
If you include a global namespaced file, it will operate on the global namespace.
グローバル空間
(PHP 5 >= 5.3.0)
名前空間の定義がない場合、すべてのクラスや関数の定義はグローバル空間に配置されます。 これは、名前空間に対応する前の PHP がサポートしていた空間です。 名前の先頭に \ をつけると、 名前空間の内部からであってもグローバル空間の名前を指定することができます。
例1 グローバル空間を指定する方法
<?php
namespace A\B\C;
/* この関数は A\B\C\fopen です */
function fopen() {
/* ... */
$f = \fopen(...); // グローバルな fopen をコールします
return $f;
}
?>
xmarcos at gmail dot com
21-May-2012 07:08
routinet
28-Aug-2011 11:22
Included files will default to the global namespace.
<?php
//test.php
namespace test {
include 'test1.inc';
echo '-',__NAMESPACE__,'-<br />';
}
?>
<?php
//test1.inc
echo '-',__NAMESPACE__,'-<br />';
?>
Results of test.php:
--
-test-
