Namespacing in PHP
From: PHP.net
In the broadest definition namespaces are a way of encapsulating items. This can be seen as an abstract concept in many places. For example, in any operating system directories serve to group related files, and act as a namespace for the files within them. As a concrete example, the file
foo.txtcan exist in both directory/home/gregand in/home/other, but two copies offoo.txtcannot co-exist in the same directory. In addition, to access thefoo.txtfile outside of the/home/gregdirectory, we must prepend the directory name to the file name using the directory separator to get/home/greg/foo.txt. This same principle extends to namespaces in the programming world.
Defining
From: PHP.net
Namespaces are declared using the
namespacekeyword. A file containing a namespace must declare thenamespaceat the top of the file before any other code - with one exception: thedeclarekeyword.
namespace MyProject;
const CONNECT_OK = 1;
class Connection { /* ... */ }
function connect() { /* ... */ }