mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-18 03:21:18 +02:00
Moving to Post structure.
Lots of changes breaking out subsections into posts and programmatically generating ToC, main page content, and Back to Top links.
This commit is contained in:
19
_posts/03-03-01-Namespaces.md
Normal file
19
_posts/03-03-01-Namespaces.md
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
isChild: true
|
||||
---
|
||||
|
||||
## Namespaces
|
||||
|
||||
As mentioned above, the PHP community has a lot of developers creating lots of code. This means that one library's PHP code may use the same class name as another library. When both libraries are used in the same namespace, they collide and cause trouble.
|
||||
|
||||
_Namespaces_ solve this problem. As described in the PHP reference manual, namespaces may be compared to operating system directories that _namespace_ files; two files with the same name may co-exist in separate directories. Likewise, two PHP classes with the same name may co-exist in separate PHP namespaces. It's as simple as that.
|
||||
|
||||
It is important for you to namespace your code so that it may be used by other developers without fear of colliding with other libraries.
|
||||
|
||||
One recommended way to use namespaces is outlined in [PSR-0](psr0), which aims to provide a standard file, class and namespace convention to allow plug-and-play code.
|
||||
|
||||
* [Read about Namespaces][namespaces]
|
||||
* [Read about PSR-0][psr0]
|
||||
|
||||
[namespaces]: http://php.net/manual/en/language.namespaces.php
|
||||
[psr0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
|
Reference in New Issue
Block a user