Many open source systems, such as the oscommerce framework, will find use in the source code, such as the oscommerce framework in the index.php file in the source code:
Use Oscommerce\om\core\autoloader;
Use oscommerce\om\core\oscom;
In fact, PHP's use keyword is introduced from the php5.3 version above. Its role is to alias an external reference. This is an important feature of namespaces, similar to the creation of a connection flag for a file or directory on a unix-based file system.
The PHP namespace supports three alias types (or references):
1. Alias a class
2. Alias for an interface
3. Alias a namespace
All three of these methods are done using the USE keyword. Here are some examples of three aliases:
Example #1 importing/aliasing with the use operator
<?php
Namespacefoo;
Usemy\full\classnameasanother;
Thisisthesameasusemy\full\nsnameasnsname
Usemy\full\nsname;
Importingaglobalclass
Usearrayobject;
$obj =newnamespace\another;//instantiatesobjectofclassfoo\another
$obj =newanother;// Instantiatesobjectofclassmy\full\classname
Nsname\subns\func ();//callsfunctionmy\full\nsname\subns\func
$a =newarrayobject (Array (1));//instantiatesobjectofclassarrayobject
//withoutthe "Usearrayobject" Wewouldinstantiateanobjectofclassfoo\arrayobject
?>
Note that for the named name, the full name contains the separator, such as Foo\bar, and can not use Foobar, and "\foo\bar" the head of the "\" is not necessary, and do not recommend this. The introduction name must be a full name and has no program associated with the current namespace .
PHP can also declare multiple on the same line, equivalent to the above wording
<?php
Usemy\full\classnameasanother,my\full\nsname;
$obj =newanother;//instantiatesobjectofclassmy\full\classname
nsname\subns\func ();//callsfunctionmy\full\ Nsname\subns\func
?>
It is also worth saying that the introduction is performed at compile time, so the alias does not affect the dynamic class , for example:
<?php
Usemy\full\classnameasanother,my\full\nsname;
$obj =newanother;//instantiatesobjectofclassmy\full\classname
$a = ' Another ';
$obj = New $a; Instantiates object of class Another
?>
Here because the variable $a assigned to the ' Another ', when compiling, will $a positioning to Classname.
More detailed usage the reader can consult the PHP manual or follow the relevant articles of this site.