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

search for in the

Mehrere Namespaces in der selben Datei definieren> <Namespaces definieren
[edit] Last updated: Fri, 17 May 2013

view this page in

Unter-Namespaces deklarieren

(PHP 5 >= 5.3.0)

Ähnlich wie Verzeichnisse und Dateien hat ein PHP-Namespace auch die Möglichkeit, eine Hierarchie von Namespacenamen zu beinhalten. Ein Namespace kann also mit Unterebenen definiert werden:

Beispiel #1 Einen einzelnen Namespace mit einer Hierarchie deklarieren

<?php
namespace MyProject\Sub\Level;

const 
CONNECT_OK 1;
class 
Connection /* ... */ }
function 
connect() { /* ... */  }

?>
Das obige Beispiel erzeugt eine Konstante MyProject\Sub\Level\CONNECT_OK, die Klasse MyProject\Sub\Level\Connection und die Funktion MyProject\Sub\Level\connect.



add a note add a note User Contributed Notes Unter-Namespaces deklarieren - [1 notes]
up
-16
AmitU
3 months ago
Note that constant in the example will be global and not in the namespace only.

To do it in the namespace only put the namespace path in the definition

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