<div class="sect1" lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both;"><a name="function.require">
</a>
<tt class="function">
require
</tt>
</h2>
</div>
</div>
</div>
<p>
The
<tt class="function">
require
</tt>
statement includes and evaluates the specific file.
</p>
<p>
<tt class="function">
require
</tt>
includes and evaluates a specific file. Detailed information on how this inclusion works is described in the documentation for
<tt class="function">
include
</tt>
.
</p>
<p>
<tt class="function">
require
</tt>
and
<tt class="function">
include
</tt>
are identical in every way except how they handle failure.
<tt class="function">
include
</tt>
produces a
<a href="apfs03.html#internal.e-warning" title="E_WARNING">
Warning
</a>
while
<tt class="function">
require
</tt>
results in a
<a href="apfs03.html#internal.e-error" title="E_ERROR">
Fatal Error
</a>
. In other words, don't hesitate to use
<tt class="function">
require
</tt>
if you want a missing file to halt processing of the page.
<tt class="function">
include
</tt>
does not behave this way, the script will continue regardless. Be sure to have an appropriate
<a href="aphs02.html#ini.include-path">
include_path
</a>
setting as well.
</p>
<p>
</p>
<div class="example">
<a name="id531194">
</a>
<p class="title">
<b>
Example 16.4. Basic
<tt class="function">
require
</tt>
examples
</b>
</p>
<pre class="programlisting">
<?php require 'prepend.php'; require $somefile; require ('somefile.txt'); ?
>
</pre>
</div>
<p>
</p>
<p>
See the
<tt class="function">
include
</tt>
documentation for more examples.
</p>
<p>
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">
Note
</h3>
<p>
Prior to PHP 4.0.2, the following applies:
<tt class="function">
require
</tt>
will always attempt to read the target file, even if the line it's on never executes. The conditional statement won't affect
<tt class="function">
require
</tt>
. However, if the line on which the
<tt class="function">
require
</tt>
occurs is not executed, neither will any of the code in the target file be executed. Similarly, looping structures do not affect the behaviour of
<tt class="function">
require
</tt>
. Although the code contained in the target file is still subject to the loop, the
<tt class="function">
require
</tt>
itself happens only once.
</p>
</div>
<p>
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">
Note
</h3>
<p>
Because this is a language construct and not a function, it cannot be called using
<a href="ch17s04.html" title="Variable functions">
variable functions
</a>
</p>
</div>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">
Warning
</h3>
<p>
Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if
<a href="rn37.html#ini.allow-url-fopen">
allow_url_fopen
</a>
is enabled.
</p>
</div>
<p>
See also
<tt class="function">
include
</tt>
,
<tt class="function">
require_once
</tt>
,
<tt class="function">
include_once
</tt>
,
<tt class="function">
eval
</tt>
,
<tt class="function">
file
</tt>
,
<tt class="function">
readfile
</tt>
,
<tt class="function">
virtual
</tt>
and
<a href="aphs02.html#ini.include-path">
include_path
</a>
.
</p>
</div>
</body>