downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Namespaces verwenden: Rückgriff auf globale Funktion/Konstante> <Namespaces verwenden: Importieren/Aliase
[edit] Last updated: Fri, 17 May 2013

view this page in

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;
}
?>



add a note add a note User Contributed Notes Globaler Namensraum - [2 notes]
up
2
xmarcos at gmail dot com
1 year ago
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.
up
2
routinet
1 year ago
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-

 
show source | credits | stats | sitemap | contact | advertising | mirror sites