Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From <a href="http://www.php.net/manual/en/language.namespaces.rationale.php" rel="nofollow noreferrer">php.net</a>:</p> <blockquote> <p>What are namespaces? 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.txt can exist in both directory /home/greg and in /home/other, but two copies of foo.txt cannot co-exist in the same directory. In addition, to access the foo.txt file outside of the /home/greg directory, 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.</p> </blockquote> <p>So, as another poster mentioned, namespaces can be used to group items together.</p> <p>To see why this might be useful, suppose you want to write a plug-in for, say, Wordpress, and you want to create a class named 'MyClass'. The trouble is, though, you have no idea if some other developer has already written another Wordpress plug-in using a class named 'MyClass'. So to avoid naming conflicts, instead you name your class 'MyPluginMyClass'. This is annoying, but it probably avoids naming conflicts.</p> <p>But then comes the release of PHP 5.3, which finally supports namespaces (let's assume, too, that Wordpress and all of the servers on which it is deployed upgrade to PHP 5.3). Now you can create a namespace, say 'MyPlugin', and encapsulate 'MyClass' within it. Having done this, you can publish your plugin without worrying that your version of 'MyClass' will conflict with someone else's version of 'MyClass'.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload