language/namespaces.xml
d4d5216e7a965ca194f6b1c9dee84cecab2674e5
...
...
@@ -6,6 +6,7 @@
6
6

7
7
<sect1 xml:id="language.namespaces.rationale">
8
8
<title>Namespaces overview</title>
9
+
<titleabbrev>Overview</titleabbrev>
9
10
<?phpdoc print-version-for="namespaces"?>
10
11
<simpara>
11
12
What are namespaces? In the broadest definition namespaces are a way of encapsulating
...
...
@@ -86,6 +87,7 @@ echo constant($d); // see "Namespaces and dynamic language features" section
86
87

87
88
<sect1 xml:id="language.namespaces.definition">
88
89
<title>Defining namespaces</title>
90
+
<titleabbrev>Namespaces</titleabbrev>
89
91
<?phpdoc print-version-for="namespaces"?>
90
92
<para>
91
93
Although any valid PHP code can be contained within a namespace, only the following
...
...
@@ -139,6 +141,7 @@ namespace MyProject; // fatal error - namespace must be the first statement in t
139
141
</sect1>
140
142
<sect1 xml:id="language.namespaces.nested">
141
143
<title>Declaring sub-namespaces</title>
144
+
<titleabbrev>Sub-namespaces</titleabbrev>
142
145
<?phpdoc print-version-for="namespaces"?>
143
146
<para>
144
147
Much like directories and files, PHP namespaces also contain the ability to specify
...
...
@@ -166,6 +169,7 @@ function connect() { /* ... */ }
166
169
</sect1>
167
170
<sect1 xml:id="language.namespaces.definitionmultiple">
168
171
<title>Defining multiple namespaces in the same file</title>
172
+
<titleabbrev>Defining multiple namespaces in the same file</titleabbrev>
169
173
<?phpdoc print-version-for="namespaces"?>
170
174
<para>
171
175
Multiple namespaces may also be declared in the same file. There are two allowed
...
...
@@ -281,6 +285,7 @@ echo MyProject\Connection::start();
281
285
</sect1>
282
286
<sect1 xml:id="language.namespaces.basics">
283
287
<title>Using namespaces: Basics</title>
288
+
<titleabbrev>Basics</titleabbrev>
284
289
<?phpdoc print-version-for="namespaces"?>
285
290
<para>
286
291
Before discussing the use of namespaces, it is important to understand how PHP
...
...
@@ -291,7 +296,7 @@ echo MyProject\Connection::start();
291
296
<listitem>
292
297
<simpara>
293
298
Relative file name like <literal>foo.txt</literal>. This resolves to
294
-
<literal>currentdirectory/foo.txt</literal> where currentdirectory is the
299
+
<literal>currentdirectory/foo.txt</literal> where <literal>currentdirectory</literal> is the
295
300
directory currently occupied. So if the current directory is
296
301
<literal>/home/foo</literal>, the name resolves to <literal>/home/foo/foo.txt</literal>.
297
302
</simpara>
...
...
@@ -404,7 +409,7 @@ echo \Foo\Bar\FOO; // resolves to constant Foo\Bar\FOO
404
409
Note that to access any global
405
410
class, function or constant, a fully qualified name can be used, such as
406
411
<function>\strlen</function> or <classname>\Exception</classname> or
407
-
<literal>\INI_ALL</literal>.
412
+
\<constant>INI_ALL</constant>.
408
413
<example>
409
414
<title>Accessing global classes, functions and constants from within a namespace</title>
410
415
<programlisting role="php">
...
...
@@ -427,6 +432,7 @@ $c = new \Exception('error'); // instantiates global class Exception
427
432
</sect1>
428
433
<sect1 xml:id="language.namespaces.dynamic">
429
434
<title>Namespaces and dynamic language features</title>
435
+
<titleabbrev>Namespaces and dynamic language features</titleabbrev>
430
436
<?phpdoc print-version-for="namespaces"?>
431
437
<para>
432
438
PHP's implementation of namespaces is influenced by its dynamic nature as a programming
...
...
@@ -504,7 +510,8 @@ echo constant('namespacename\constname'), "\n"; // also prints namespaced
504
510
</para>
505
511
</sect1>
506
512
<sect1 xml:id="language.namespaces.nsconstants">
507
-
<title>namespace keyword and __NAMESPACE__ constant</title>
513
+
<title>The namespace keyword and __NAMESPACE__ magic constant</title>
514
+
<titleabbrev>namespace keyword and __NAMESPACE__</titleabbrev>
508
515
<?phpdoc print-version-for="namespaces"?>
509
516
<para>
510
517
PHP supports two ways of abstractly accessing elements within the current namespace,
...
...
@@ -601,6 +608,7 @@ $b = namespace\CONSTANT; // assigns value of constant CONSTANT to $b
601
608

602
609
<sect1 xml:id="language.namespaces.importing">
603
610
<title>Using namespaces: Aliasing/Importing</title>
611
+
<titleabbrev>Aliasing and Importing</titleabbrev>
604
612
<?phpdoc print-version-for="namespaces"?>
605
613
<para>
606
614
The ability to refer to an external fully qualified name with an alias, or importing,
...
...
@@ -608,7 +616,7 @@ $b = namespace\CONSTANT; // assigns value of constant CONSTANT to $b
608
616
ability of unix-based filesystems to create symbolic links to a file or to a directory.
609
617
</para>
610
618
<para>
611
-
PHP can alias(/import) constants, functions, classes, interfaces, and namespaces.
619
+
PHP can alias(/import) constants, functions, classes, interfaces, traits, enums and namespaces.
612
620
</para>
613
621
<para>
614
622
Aliasing is accomplished with the <literal>use</literal> operator.
...
...
@@ -778,6 +786,7 @@ use const some\namespace\{ConstA, ConstB, ConstC};
778
786
</sect1>
779
787
<sect1 xml:id="language.namespaces.global">
780
788
<title>Global space</title>
789
+
<titleabbrev>Global space</titleabbrev>
781
790
<?phpdoc print-version-for="namespaces"?>
782
791
<para>
783
792
Without any namespace definition, all class and function definitions are
...
...
@@ -805,7 +814,8 @@ function fopen() {
805
814
</para>
806
815
</sect1>
807
816
<sect1 xml:id="language.namespaces.fallback">
808
-
<title>Using namespaces: fallback to global function/constant</title>
817
+
<title>Using namespaces: fallback to the global space for functions and constants</title>
818
+
<titleabbrev>Fallback to global space</titleabbrev>
809
819
<?phpdoc print-version-for="namespaces"?>
810
820
<para>
811
821
Inside a namespace, when PHP encounters an unqualified Name in a class name, function or
...
...
@@ -863,6 +873,7 @@ if (is_array('hi')) { // prints "is not array"
863
873

864
874
<sect1 xml:id="language.namespaces.rules">
865
875
<title>Name resolution rules</title>
876
+
<titleabbrev>Name resolution rules</titleabbrev>
866
877
<?phpdoc print-version-for="namespaces"?>
867
878
<para>
868
879
For the purposes of these resolution rules, here are some important definitions:
...
...
@@ -945,8 +956,8 @@ if (is_array('hi')) { // prints "is not array"
945
956
class/namespace import table, function names according to the function import table and
946
957
constants according to the constant import table. For example, after
947
958
<literal>use A\B\C;</literal> a usage such as <literal>new C()</literal> resolves to the name
948
-
<literal>A\B\C()</literal>. Similarly, after <literal>use function A\B\fn;</literal> a usage
949
-
such as <literal>fn()</literal> resolves to the name <literal>A\B\fn</literal>.
959
+
<literal>A\B\C()</literal>. Similarly, after <literal>use function A\B\foo;</literal> a usage
960
+
such as <literal>foo()</literal> resolves to the name <literal>A\B\foo</literal>.
950
961
</simpara>
951
962
</listitem>
952
963
<listitem>
...
...
@@ -1049,6 +1060,7 @@ A\B::foo(); // calls method "foo" of class "B" from namespace "A\A"
1049
1060
</sect1>
1050
1061
<sect1 xml:id="language.namespaces.faq">
1051
1062
<title>FAQ: things you need to know about namespaces</title>
1063
+
<titleabbrev>FAQ</titleabbrev>
1052
1064
<?phpdoc print-version-for="namespaces"?>
1053
1065
<para>
1054
1066
This FAQ is split into two sections: common questions, and some specifics of
...
...
@@ -1135,7 +1147,7 @@ A\B::foo(); // calls method "foo" of class "B" from namespace "A\A"
1135
1147
<listitem>
1136
1148
<simpara>
1137
1149
<link linkend="language.namespaces.faq.builtinconst">Cannot override special
1138
-
constants NULL, TRUE, FALSE, ZEND_THREAD_SAFE or ZEND_DEBUG_BUILD</link>
1150
+
constants &null;, &true; or &false;</link>
1139
1151
</simpara>
1140
1152
</listitem>
1141
1153
</orderedlist>
...
...
@@ -1508,7 +1520,7 @@ $a = \Bar\FOO; // fatal error, undefined namespace constant Bar\FOO
1508
1520
</para>
1509
1521
</sect2>
1510
1522
<sect2 xml:id="language.namespaces.faq.builtinconst">
1511
-
<title>Cannot override special constants NULL, TRUE, FALSE, ZEND_THREAD_SAFE or ZEND_DEBUG_BUILD</title>
1523
+
<title>Cannot override special constants &null;, &true; or &false;</title>
1512
1524
<para>
1513
1525
Any attempt to define a namespaced constant that is a special, built-in constant
1514
1526
results in a fatal error
1515
1527