<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.exit.php',
    1 => 'exit',
    2 => 'Terminate the current script with a status code or message',
  ),
  'up' => 
  array (
    0 => 'ref.misc.php',
    1 => 'Misc. Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.eval.php',
    1 => 'eval',
  ),
  'next' => 
  array (
    0 => 'function.get-browser.php',
    1 => 'get_browser',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/misc/functions/exit.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.exit" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">exit</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">exit</span> &mdash; <span class="dc-title">Terminate the current script with a status code or message</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.exit-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>exit</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$status</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.never.php" class="type never">never</a></span></div>

  <p class="simpara">
   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"><strong>exit()</strong></span> is called.
   However, <a href="language.exceptions.php#language.exceptions.finally" class="link"><code class="literal">finally</code></a> blocks are never executed.
  </p>
  <p class="simpara">
   An exit code of <code class="literal">0</code> is used to indicate that the program
   succeeded in its tasks.
   Any other value indicates some sort of error occurred during execution.
  </p>
  <p class="simpara">
   <span class="function"><strong>exit()</strong></span> is a special function,
   because it has a dedicated token in the parser,
   as such it can be used like a statement (i.e. without parentheses) to
   terminate the script with the default status code.
  </p>
  <div class="caution"><strong class="caution">Attenzione</strong>
   <p class="simpara">
    It is not possible to disable, or create a namespaced function shadowing
    the global <span class="function"><strong>exit()</strong></span> function.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.exit-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">status</code></dt>
    <dd>
     <span class="simpara">
      If <code class="parameter">status</code> is a string,
      this function prints the <code class="parameter">status</code> just before exiting.
      The exit code returned by PHP is <code class="literal">0</code>.
     </span>
     <p class="para">
      If <code class="parameter">status</code> is an <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>,
      the exit code returned by PHP will be <code class="parameter">status</code>.
      <blockquote class="note"><p><strong class="note">Nota</strong>: 
       <span class="simpara">
        Exit codes should be in the range <code class="literal">0</code> to <code class="literal">254</code>,
        the exit code <code class="literal">255</code> is reserved by PHP and should not be used.
       </span>
      </p></blockquote>
     </p>
     <div class="warning"><strong class="warning">Avviso</strong>
      <p class="simpara">
       Prior to PHP 8.4.0, <span class="function"><strong>exit()</strong></span> did not follow PHP&#039;s standard
       <a href="language.types.type-juggling.php#language.types.type-juggling.function" class="link">type juggling semantics</a>,
       nor respect the
       <a href="language.types.declarations.php#language.types.declarations.strict" class="link"><code class="literal">strict_types</code></a>
       declare.
      </p>
      <p class="simpara">
       Any value not of type <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> was cast to <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
       including <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> and <span class="type"><a href="language.types.array.php" class="type array">array</a></span> values.
       As of PHP 8.4.0, it follows the usual type juggling semantics and throws a
       <span class="exceptionname"><a href="class.typeerror.php" class="exceptionname">TypeError</a></span> on invalid values.
      </p>
     </div>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.exit-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   As this terminates the PHP script, no value is returned.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.exit-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.4.0</td>
      <td>
       <span class="function"><strong>exit()</strong></span> is now a proper function,
       therefore it follows the usual
       <a href="language.types.type-juggling.php#language.types.type-juggling.function" class="link">type juggling semantics</a>
       is affected by the
       <a href="language.types.declarations.php#language.types.declarations.strict" class="link"><code class="literal">strict_types</code></a>
       declare, can be called with named arguments, and be a
       <a href="functions.variable-functions.php" class="link">variable functions</a>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.exit-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 Basic <span class="function"><strong>exit()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// exit program normally<br /></span><span style="color: #007700">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 /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <div class="example" id="example-2">
   <p><strong>Example #2 <span class="function"><strong>exit()</strong></span> example with a <span class="type"><a href="language.types.string.php" class="type string">string</a></span></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">?&gt;</span></span></code></div>
   </div>

  </div>
  <div class="example" id="example-3">
   <p><strong>Example #3 Shutdown functions and destructors run regardless</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Shutdown: shutdown()
Destruct: Foo::__destruct()</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-4">
   <p><strong>Example #4 <span class="function"><strong>exit()</strong></span> as a statement</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// exit program normally with exit code 0<br /></span><span style="color: #007700">exit;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.exit-notes">
  <h3 class="title">Note</h3>
  <div class="warning"><strong class="warning">Avviso</strong>
   <p class="simpara">
    Prior to PHP 8.4.0, <span class="function"><strong>exit()</strong></span> was a language construct
    and not a function, therefore it was not possible to call it using
    <a href="functions.variable-functions.php" class="link">variable functions</a>,
    or <a href="functions.arguments.php#functions.named-arguments" class="link">named arguments</a>.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.exit-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><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>
   <li><a href="function.register-shutdown-function.php" class="link">Shutdown functions</a></li>
   <li><a href="language.oop5.decon.php#language.oop5.decon.destructor" class="link">object destructors</a></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>