The PHP community has lots of developers creating lots of code. This means that one’s PHP code might use the same class name as another. When both libraries are used in the same namespaces (usually the global namespace), they collide and cause trouble. Namespaces solve this problem.

For Java programmers, namespaces could be lightly equated to packages. The package declaration is normally the 1st line of code in your class. Namespaces have the same priority in PHP with the exception of the declare keyword.

Before namespaces were introduced in PHP version 5.3, developers used to write Extra_Long_Class_Names, with lots of underscores to make reduce the probability of another person using the same name their class. This is no longer a necessity since namespaces  provide a way to group related classes, interfaces, traits and constants.

– See more at: Classmite

Advertisements