Skip to Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

7.11 Funktionen und Klassen aus dem globalen Namensraum verwenden

Problem

In Ihrem Programm machen Sie vom Namespace-Feature Gebrauch (ab PHP 5.3). Sie haben eine Funktion geschrieben, die auch PHP im globalen Namensraum unter dem gleichen Funktionsnamen bereitstellt. Sie wollen nun diese globale Funktion und nicht die in Ihrem Quellcode deklarierte lokale Funktion aufrufen.

Lösung

Wenn Sie einem Namen (z.B. einem Funktions- oder Klassennamen) einen Backslash voranstellen, wird der Name im globalen Namensraum gesucht, unabhängig davon, in welchem Subnamespace sich Ihr Code befindet:

namespace de\oreilly\phpckbk {
    function strlen($str) {
        return 99;
    }
    print strlen('Hallo Welt!');
    print \strlen('Hallo Welt!');
}
99
11

Diskussion

In obigem Beispiel wird ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi

Publisher Resources

ISBN: 9783868993271Purchase book