Source of: /manual/fa/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 => 'fa',
),
'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>
<div class="refsect1 description" id="refsect1-function.exit-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.
<a href="function.register-shutdown-function.php" class="link">Shutdown functions</a>
and <a href="language.oop5.decon.php#language.oop5.decon.destructor" class="link">object destructors</a>
will always be executed even if <span class="function"><b>exit()</b></span> is called.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.exit-parameters">
<h3 class="title">Parameters</h3>
<p class="para">
<dl>
<dt>
<span class="term"><i><tt class="parameter">status</tt></i></span>
<dd>
<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 <span class="type"><a href="language.types.integer.php" class="type integer">integer</a></span>, that
value will be used as the exit status and not printed. 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 class="note"><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 <span class="type"><a href="language.types.integer.php" class="type integer">integer</a></span>.
</span>
</p></blockquote>
</dd>
</dt>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.exit-returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
No value is returned.
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.exit-examples">
<h3 class="title">Examples</h3>
<p class="para">
<div class="example" id="example-3135">
<p><b>Example #1 <span class="function"><b>exit()</b></span> example</b></p>
<div class="example-contents">
<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 class="para">
<div class="example" id="example-3136">
<p><b>Example #2 <span class="function"><b>exit()</b></span> status example</b></p>
<div class="example-contents">
<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 class="para">
<div class="example" id="example-3137">
<p><b>Example #3 Shutdown functions and destructors run regardless</b></p>
<div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Foo<br /></span><span style="color: #007700">{<br /> public function </span><span style="color: #0000BB">__destruct</span><span style="color: #007700">()<br /> {<br /> echo </span><span style="color: #DD0000">'Destruct: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">__METHOD__ </span><span style="color: #007700">. </span><span style="color: #DD0000">'()' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /> }<br />}<br /><br />function </span><span style="color: #0000BB">shutdown</span><span style="color: #007700">()<br />{<br /> echo </span><span style="color: #DD0000">'Shutdown: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">__FUNCTION__ </span><span style="color: #007700">. </span><span style="color: #DD0000">'()' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$foo </span><span style="color: #007700">= new </span><span style="color: #0000BB">Foo</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">register_shutdown_function</span><span style="color: #007700">(</span><span style="color: #DD0000">'shutdown'</span><span style="color: #007700">);<br /><br />exit();<br />echo </span><span style="color: #DD0000">'This will not be output.'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents"><p>The above example will output:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Shutdown: shutdown()
Destruct: Foo::__destruct()
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.exit-notes">
<h3 class="title">Notes</h3>
<blockquote class="note"><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 class="note"><p><b class="note">Note</b>:
<p class="para">
This language construct is equivalent to <span class="function"><a href="function.die.php" class="function">die()</a></span>.
</p>
</p></blockquote>
</div>
<div class="refsect1 seealso" id="refsect1-function.exit-seealso">
<h3 class="title">See Also</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="function.register-shutdown-function.php" class="function" rel="rdfs-seeAlso">register_shutdown_function()</a> - Register a function for execution on shutdown</span></li>
</ul>
</p>
</div>
</div><?php manual_footer(); ?>