International PHP Conference Munich 2025

Unter-Namespaces deklarieren

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Ä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

User Contributed Notes

There are no user contributed notes for this page.
To Top

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant