Home > Article > Backend Development > What is the php namespace child namespace?
In the previous article, we learned about namespaces and how to define namespaces. If necessary, please read "php namespace: How to define space?" 》. This time we introduce sub-namespaces to you, you can refer to them if necessary.
In PHP, namespaces can help us do many things. We can prevent the names we define from conflicting with PHP internal names, and we can also give the identifier a shorter name to make it easier for us to use and read.
And it also has an important function, but let us look at a small example first, and then we will talk about what this function is.
<?php namespace MyProject\Sub\Level; //声明分层次的单个命名空间 const CONNECT_OK = 1; class Connection { /* ... */ } function Connect() { /* ... */ } ?>
Let’s take a look at this and then look at the namespace in the previous article.
<?php namespace MyProject { const CONNECT_OK = 1; class Connection { /* ... */ } function connect() { /* ... */ } } namespace AnotherProject { const CONNECT_OK = 1; class Connection { /* ... */ } function connect() { /* ... */ } } ?>
Compare it carefully. Do you find any differences?
Let us shift our attention to <strong>namespace</strong>
. Are the words a little different? In the above example, there are "\#" between words. ##", and the following is just one word. Everyone can see it.
MyProject\Sub\Level\CONNECT_OK, class
MyProject\Sub\Level\Connection and function
MyProject\Sub\Level\Connect.
The above is the detailed content of What is the php namespace child namespace?. For more information, please follow other related articles on the PHP Chinese website!