Source of: /manual/en/function.exit.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.exit.php',
1 => 'exit',
),
'up' =>
array (
0 => 'ref.misc.php',
1 => 'Misc. Functions',
),
'prev' =>
array (
0 => 'function.eval.php',
1 => 'eval',
),
'next' =>
array (
0 => 'function.get-browser.php',
1 => 'get_browser',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.exit" class="refentry">
<div class="refnamediv">
<h1 class="refname">exit</h1>
<p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">exit</span> — <span class="dc-title">Output a message and terminate the current script</span></p>
</div>
<a name="function.exit.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type"><span class="type void">void</span></span> <span class="methodname"><b>exit</b></span>
([ <span class="methodparam"><span class="type">string</span> <tt class="parameter">$status</tt></span>
] )</div>
<div class="methodsynopsis dc-description">
<span class="type"><span class="type void">void</span></span> <span class="methodname"><b>exit</b></span>
( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$status</tt></span>
)</div>
<p class="para rdfs-comment">
Terminates execution of the script.
</p>
</div>
<a name="function.exit.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">status</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
If <i><tt class="parameter">status</tt></i>
is a string, this function prints the
<i><tt class="parameter">status</tt></i>
just before exiting.
</p>
<p class="para">
If <i><tt class="parameter">status</tt></i>
is an <a href="language.types.integer.php" class="type integer">integer</a>, that
value will also be used as the exit status. Exit statuses should be in
the range 0 to 254, the exit status 255 is reserved by PHP and shall
not be used. The status 0 is used to terminate the program
successfully.
</p>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
PHP >= 4.2.0 does NOT print the <i><tt class="parameter">status</tt></i>
if it is an <a href="language.types.integer.php" class="type integer">integer</a>.
</span>
</p></blockquote>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.exit.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
No value is returned.
</p>
</div>
<a name="function.exit.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 <b>exit()</b> example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /><br />$filename </span><span style="color: #007700">= </span><span style="color: #DD0000">'/path/to/data-file'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$file </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">)<br /> or exit(</span><span style="color: #DD0000">"unable to open file (</span><span style="color: #0000BB">$filename</span><span style="color: #DD0000">)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
<p class="para">
</p><div class="example">
<p><b>Example #2 <b>exit()</b> status example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">//exit program normally<br /></span><span style="color: #007700">exit;<br />exit();<br />exit(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//exit with an error code<br /></span><span style="color: #007700">exit(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />exit(</span><span style="color: #0000BB">0376</span><span style="color: #007700">); </span><span style="color: #FF8000">//octal<br /><br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div>
<a name="function.exit.notes"></a><div class="refsect1 notes">
<h3 class="title">Notes</h3>
<blockquote><p><b class="note">Note</b>: <span class="simpara">Because this is a
language construct and not a function, it cannot be called using
<a href="functions.variable-functions.php" class="link">variable functions</a></span>
</p></blockquote>
<blockquote><p><b class="note">Note</b>:
This language construct is equivalent to <a href="function.die.php" class="function">die()</a>.
<br />
</p></blockquote>
</div>
<a name="function.exit.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.register-shutdown-function.php" class="function" rel="rdfs-seeAlso">register_shutdown_function()</a> - Register a function for execution on shutdown</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>