Wikis & learning

Use a namespace for small PHP components

Two libraries can choose the same short class name. A namespace makes the complete name unambiguous.

Two libraries can choose the same short class name. A namespace makes the complete name unambiguous.

How it works

Place a namespace declaration before the class. A fully qualified reference begins with a backslash.

PHP example

<?php
namespace Catalog;
class Label {
    public function text(): string { return 'Resources'; }
}
echo (new \Catalog\Label())->text();

Expected result

Resources

Try a variation

Change the namespace and update the fully qualified name to match.