: This article mainly introduces the Namespace features of namespaces in several common languages. if you are interested in PHP tutorials, refer to it. A namespace provides a way to logically organize classes to prevent name conflicts.
Several common languages
C ++
Namespaces can be nested.
A nested namespace is a namespace defined in another namespace. A nested namespace is a nested scope. the name declared in the inner namespace will hide members with the same name declared in the outer namespace:
Int x = 20; namespace outer {int x = 10; namespace inner {int z = x ;}} int main () {std: cout <outer: inner :: z; // output 10 return0 ;}
C #
Nested namespace
The namespace is declared in the namespace declaration, and each namespace is separated.
For example:
Namespace N1.N2 {class A {} class B {}} is semantically equivalent to namespace N1 {namespace N2 {class A {} class B {}}}
Java
package cn.org.web3d.x3dpad
The namespace in Java means that as long as you have an independent top-level domain name, you can ensure the absolute uniqueness of your project.
Objective-C
All class names in Objective-C applications must be globally unique. Naming has always been a tough headache for Objective-C, compared with those elegant languages. Apple officially recommends that the class names prefixed with two letters be prepared for the official library and framework. for third-party developers, we recommend that you use three or more letters as the prefix to name your class.
PHP
namespace Vendor\Package\.....
It emphasizes that the first-level Vendor should be a unique identifier, which means that you must own a top-level domain name of {Vendor}. com to ensure the absolute uniqueness of your project. For example, when I thought about this, I immediately registered a meanir.com domain name to defend myself.
The above describes the Namespace features of namespaces in several common languages, including some content. I hope my friends who are interested in PHP tutorials will be helpful.