1. What are the namespaces in PHP?What is a namespace? "In a broad sense, namespaces are a way of encapsulating things. This abstract concept can be seen in many places. For example, in an operating system, a directory is used to group related files,
PHP namespace parsing rules
namespace name definition
Unqualified names unqualified Name
名称中不包含命名空间分隔符的标识符,例如Foo
Qualified name qualified name
名称中含有命名空间分隔符的标识符,例如:Foo\Bar
Fully qualified name fully qualified
PHP NamespacesOne of the most clear role is to solve the same name problem, PHP does not allow two functions or classes to appear the same names, otherwise it will produce a fatal error. The previous section describes what a PHP namespace is. PHP
This article mainly introduces the usage of the namespace in PHP, and analyzes the functions, usage, and precautions of the namespace in php using examples, for more information about how to use PHP namespace, see the example in this article. We
Php namespace namespace
The official statement is:
In PHP, namespaces are used to solve two types of problems when creating reusable code such as classes or functions when writing a class library or application
1. User-written code conflicts
1. What is the namespace in PHP? What is a namespace? In a broad sense, namespace is a way to encapsulate things. This abstract concept can be seen in many places. For example, a directory in the operating system is used to group related files. For
The most explicit purpose of a namespace is to solve the problem of duplicate names. In PHP, two functions or classes cannot have the same name. Otherwise, a fatal error occurs. In this case, the namespace can be solved by avoiding repeated names.
Php introduces the namespace with the & quot; split syntax, which is unique and unaccustomed to first use. In addition, it uses well-designed directory results for management, namespace management can also be implemented. I personally think that the
PHP namespace details
This article mainly introduces the namespace in PHP and explains the namespace) for more information, see
Overview
PHP's support for namespaces has gone through a difficult journey. Fortunately, PHP introduced namespaces from 5.
This article mainly introduces the PHP Namespace concise tutorial. if you need it, you can refer to this feature as mentioned in PHP5.0x. later, it was canceled and scheduled to be implemented in PHP6. The release of PHP5.3 was "in advance" again,
What is a namespace? "In a broad sense, namespace is a way to encapsulate things. This abstract concept can be seen in many places. For example, a directory in the operating system is used to group related files.
1. what is the namespace in
Namespaces are the problem of resolving duplicate names.
For example, A and B two directories have a model file;Add namespace A at the beginning of the model file named under Directory A;
namespacea;classmodel{}
Give namespace B at the beginning
PHP namespaces (namespace) are added in PHP 5.3, and if you learn C # and Java, that namespace is nothing new. However, in PHP there is a very important meaning.
The PHP namespace resolves the following two types of problems:
User-written code
When a php file declares a namespace, the class must be specified in the namespace in which the file is used, otherwise it will be an error because the class is not found in the current space, and the PHP core class will have this problem, for
PHP namespace instance description. Copy the code as follows: namespacebakbaba; functionbab () {echobi;} namespacekkk; functionk1 () {echok1;} bakbababab (); use another namespace in the kkk namespace
The code is as follows:
Namespace bak \
If this is the directory structure
This is test.class.php the inside of the code
php
这是 IndexController.class.php 下的代码
php
我想达到的效果是在 test.class.php 下不把命名空间命名成 namespace Common\Common; 而是命名为 namespace Common; 也能在 IndexController.class.
PHP namespace namespace function call class reference detailed test analysisIn this test, it is assumed that the index.php page and the test.php page are in the same root directory, which facilitates loading of test.php pages.The prerequisites are
For the namespace, the official documentation has already been very detailed [view]. I have made some practical and summary here.
The most explicit purpose of a namespace is to solve the problem of duplicate names. In PHP, two functions or classes
Php namespace and use, phpnamespaceuse
Lab code
~ /Aa. php
~ /Bb. php
1. Relationship between namespaces and file loading
I have always had a misunderstanding about namespaces and file loading. I don't need to load a namespace file?
PHP Namespace Usage Issues
This post was last edited by potency on 2014-03-20 09:46:47
test1.php:
namespace Test1;
function test ()
{
Echo __function__;
}
[/code]
test2.php
Use test1;function Test2 (){ Echo __function__;}echo Test1
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.