Home  >  Article  >  Backend Development  >  php namespace, php namespace usage_PHP tutorial

php namespace, php namespace usage_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:00:03845browse

php namespace, php namespace usage

/*First of all, the namespace exists to solve the problem of naming conflicts when referencing different classes*/

/*1. Define namespace*/
namespace My;
class A{};
namespace Your;
class A{};
/ *2. Reference namespace in the same project*/
namespace My;
class A{};
//Direct reference (use unqualified name)
$a = new A() ;
                                                                                                                                                      / /Reference the namespace starting from the root directory (fully qualified name)
$b=namespaceMyA();
namespace Myonetwo;
class A{};
namespace Your;
class A{};


use Myonetwo //If the ending is named space is the default The last paragraph is an alias, similar to adding an environment variable $obj=new twoA();
$obj=new MyonetwoA();


use MyonetwoA as My A // If it ends with a class name, it is equivalent to the shortcut



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 of all, the existence of namespace is to solve the problem of naming names in different classes. Conflict issues*/ /*1. Define namespace*/ namespace My; class A{}; na...




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn