Php namespaces

From wikinotes
Revision as of 23:41, 9 July 2020 by Will (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Namespaces work similar to java packages.
Define the namespace, the actual location of the file could be anywhere.

# /src/package/foo/bar/baz.php

namespace Foo\Bar;

class Baz
{
    // ...
}
# /src/package/foo/bar/zab.php

use Foo\Bar;

new Bar\Baz()