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.
Globaler Namensraum
(PHP 5 >= 5.3.0)
Ohne die Definition eines Namespace werden alle Klassen- und Funktionsdefinitionen im globalen Namensraum platziert, so wie dies auch in PHP geschah bevor Namespaces unterstützt wurden. Wenn man dem Namen ein \ voranstellt, so spezifiziert man, dass der Name dem globalen Namensraum angehört, auch wenn man sich im Kontext eines Namensraumes befindet.
Beispiel #1 Verwenden der Spezifikation des gloablen Namensraumes
<?php
namespace A\B\C;
/* Diese Funktion ist A\B\C\fopen */
function fopen() {
/* ... */
$f = \fopen(...); // globale Funktion fopen aufrufen
return $f;
}
?>
xmarcos at gmail dot com
21-May-2012 09:08
routinet
29-Aug-2011 01: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-
