<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
require
</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
<link rel="start" href="index.html" title="PHP Manual">
<link rel="up" href="ch16.html" title="Chapter&nbsp;16.&nbsp;Control Structures">
<link rel="prev" href="ch16s13.html" title="return">
<link rel="next" href="ch16s15.html" title="include">
</head>

<body vlink="#840084" text="black" link="#0000ff" bgcolor="white" alink="#0000ff">
<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&nbsp;16.4.&nbsp;Basic <tt class="function"> require </tt> examples </b>
</p>
<pre class="programlisting"> &lt;?php require 'prepend.php'; require $somefile; require ('somefile.txt'); ?&gt; </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>