PHP namespaces, PHP namespace usage
/* First the namespace exists in order to resolve a naming conflict problem that refers to a non-homogeneous type */
/*1. Define Namespaces */
namespace My;
Class a{};
namespace Your;
Class a{};
/*2. Referencing a namespace in the same project */
namespace My;
Class a{};
Direct references (with unqualified names)
$a = new A ();
Referencing child namespaces (using qualified names)
$obj = new Son\a ();
namespace My\son;
Class a{};
Namespace (fully qualified name) that references the beginning of the root directory
$b =namespace\my\a ();
/*3. Using use to take aliases and references (import) */
namespace My\one\two;
Class a{};
namespace Your;
Class a{};
Use \my\one\two//If the end is a namespace, the last segment is aliased by default, similar to adding environment variables
$obj =new two\a ();
$obj =new \my\one\two\a ();
Use \my\one\two\a as MyA//If the end is a class name then the class name is equivalent to a shortcut
$obj =new MyA ();
http://www.bkjia.com/PHPjc/1095473.html www.bkjia.com true http://www.bkjia.com/PHPjc/1095473.html techarticle php namespace, PHP namespace usage/* First ~ The namespace exists to resolve the issue of naming conflicts in a non-homogeneous type *//*1. Defining namespaces */namespace My; class a{}; na ...