Home > Backend Development > PHP Tutorial > php namespace, php namespace usage_PHP tutorial

php namespace, php namespace usage_PHP tutorial

WBOY
Release: 2016-07-12 09:00:03
Original
858 people have browsed it

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...




Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template