language/control-structures/include.xml
a124543dd3f6b1e5567b07420d23899e582514dc
a124543dd3f6b1e5567b07420d23899e582514dc
...
...
@@ -5,7 +5,7 @@
5
5
<title>include</title>
6
6
<?phpdoc print-version-for="include"?>
7
7
<simpara>
8
-
The <literal>include</literal> statement includes and evaluates
8
+
The <literal>include</literal> expression includes and evaluates
9
9
the specified file.
10
10
</simpara>
11
11
<simpara>
...
...
@@ -17,11 +17,17 @@
17
17
isn't found in the <link linkend="ini.include-path">include_path</link>,
18
18
<literal>include</literal> will finally check in the calling script's own
19
19
directory and the current working directory before failing. The
20
-
<literal>include</literal> construct will emit a
21
-
<link linkend="errorfunc.constants.errorlevels.e-warning">warning</link> if
20
+
<literal>include</literal> construct will emit an
21
+
<constant>E_WARNING</constant> if
22
22
it cannot find a file; this is different behavior from
23
-
<function>require</function>, which will emit a
24
-
<link linkend="errorfunc.constants.errorlevels.e-error">fatal error</link>.
23
+
<function>require</function>, which will emit an
24
+
<constant>E_ERROR</constant>.
25
+
</simpara>
26
+
<simpara>
27
+
Note that both <literal>include</literal> and <literal>require</literal>
28
+
raise additional <constant>E_WARNING</constant>s, if the file cannot be
29
+
accessed, before raising the final <constant>E_WARNING</constant> or
30
+
<constant>E_ERROR</constant>, respectively.
25
31
</simpara>
26
32
<simpara>
27
33
If a path is defined — whether absolute (starting with a drive letter
...
...
@@ -78,7 +84,7 @@ echo "A $color $fruit"; // A green apple
78
84
though it had been defined inside that function. So, it will follow
79
85
the variable scope of that function.
80
86
An exception to this rule are <link
81
-
linkend="language.constants.predefined">magic constants</link> which are
87
+
linkend="language.constants.magic">magic constants</link> which are
82
88
evaluated by the parser before the include occurs.
83
89
</simpara>
84
90
<para>
...
...
@@ -151,12 +157,6 @@ include 'file.php?foo=1&bar=2';
151
157
152
158
// Works.
153
159
include 'http://www.example.com/file.php?foo=1&bar=2';
154
-
155
-
$foo = 1;
156
-
$bar = 2;
157
-
include 'file.txt'; // Works.
158
-
include 'file.php'; // Works.
159
-
160
160
?>
161
161
]]>
162
162
</programlisting>
...
...
@@ -203,7 +203,7 @@ include 'file.php'; // Works.
203
203
<programlisting role="php">
204
204
<![CDATA[
205
205
<?php
206
-
// won't work, evaluated as include(('vars.php') == TRUE), i.e. include('')
206
+
// won't work, evaluated as include(('vars.php') == TRUE), i.e. include('1')
207
207
if (include('vars.php') == TRUE) {
208
208
echo 'OK';
209
209
}
...
...
@@ -264,9 +264,8 @@ echo $bar; // prints 1
264
264
<para>
265
265
If there are functions defined in the included file, they can be used in the
266
266
main file independent if they are before <function>return</function> or after.
267
-
If the file is included twice, PHP 5 issues fatal error because functions
268
-
were already declared, while PHP 4 doesn't complain about functions
269
-
defined after <function>return</function>.
267
+
If the file is included twice, PHP will raise a fatal error because the
268
+
functions were already declared.
270
269
It is recommended to use <function>include_once</function> instead of
271
270
checking if the file was already included and conditionally return inside
272
271
the included file.
273
272