Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Namespace Stack

<?php

namespace {
    const A = 'in \\';
}

namespace A {
    const A = 'in A';
}

namespace A\B {
    const A = 'in A\\B';
}

namespace A\B\C {
    echo A;
}

This is a reminder that namespaces are not nested, but are merely prefixes. Hence, there is the current namespace, and the global one for the occasional fallback, but nothing in between. Namespaces are not folders, even when they are stored as such.

See Also

PHP Features

Last updated: 09 November 2026