PHP's namespace (namespace) is only available after php5.3. This concept is already very early in C #, and the namespace in PHP is actually the same as the C # concept.
Why should I use namespace in PHP?
Assuming that you do not use namespace, the name of each class in a project must be fixed. Because PHP has a file that corresponds to a class name, whether it's calling AutoLoad or calling a loaded class at new. So when there is no namespace, we think of various naming conventions to distinguish different classes, such as Project1_school1_class1_student or project2_school_class_student.
The introduction of namespace can be effectively circumvented, a namespace equivalent to a file path, when looking for this class, it will go to the corresponding file path to find the class definition file.
Defined
!--? php namespace Myproject; Use
!--? php use Myproject/school; Alias
!--? php use Myproject/school as School1; The alias Namespace is parsed at run time. Use is equivalent to a declaration that does not parse and load. For example:
test.php
!--? phpuse my\name;require_once ("/home/yejianfeng/handcode/ Test/namespace1.php "); $a = new my\name\a (); $a--->print1 ();
namespace1.php
!--? phpnamespace my\name;class A {public Function Print1 () { Echo 11; }}