<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.error-handling.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'language.error-handling.diagnostic.php',
    1 => 'Diagnostic errors',
    2 => 'Diagnostic errors',
  ),
  'up' => 
  array (
    0 => 'language.error-handling.php',
    1 => 'Error Handling',
  ),
  'prev' => 
  array (
    0 => 'language.error-handling.throwable.php',
    1 => 'Throwable errors',
  ),
  'next' => 
  array (
    0 => 'language.fibers.php',
    1 => 'Fibers',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/error-handling.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.error-handling.diagnostic" class="sect1">
  <h2 class="title">Diagnostic errors</h2>
  <p class="simpara">
   Diagnostic errors, also known as traditional errors, are used to signal a
   number of different conditions, and can be displayed and/or logged as required.
   By default PHP will report all diagnostic errors. (Prior to PHP 8.0,
   <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong> and <strong><code><a href="errorfunc.constants.php#constant.e-deprecated">E_DEPRECATED</a></code></strong>
   diagnostics were not reported by default.)
  </p>
  <p class="simpara">
   In contrast to <span class="exceptionname"><a href="class.throwable.php" class="exceptionname">Throwable</a></span> errors, most diagnostic
   errors do <em>not</em> disrupt the normal flow of execution.
   Fatal diagnostics, such as <strong><code><a href="errorfunc.constants.php#constant.e-error">E_ERROR</a></code></strong>, terminate the script.
  </p>
  <p class="simpara">
   Which diagnostics are reported and which are ignored is controlled by the
   <a href="errorfunc.configuration.php#ini.error-reporting" class="link"><code class="parameter">error_reporting</code></a>
   <var class="filename">php.ini</var> directive, or at runtime by calling <span class="function"><a href="function.error-reporting.php" class="function">error_reporting()</a></span>.
   It is strongly recommended that the configuration directive be set,
   as some errors can occur before execution of your script begins.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="simpara">
    In a development environment,
    <a href="errorfunc.configuration.php#ini.error-reporting" class="link"><code class="parameter">error_reporting</code></a>
    should always be set to <strong><code><a href="errorfunc.constants.php#constant.e-all">E_ALL</a></code></strong> to be aware of and fix
    issues raised by PHP.
    However, in production the level of verbosity could be reduced to
    <code class="code">E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED</code>, but in many cases
    <strong><code><a href="errorfunc.constants.php#constant.e-all">E_ALL</a></code></strong> is still appropriate, as it may provide early
    warning of potential issues.
   </p>
  </p></blockquote>

  <p class="simpara">
   What happens to the diagnostics depends on two further <var class="filename">php.ini</var> directives.
   <a href="errorfunc.configuration.php#ini.display-errors" class="link"><code class="parameter">display_errors</code></a>
   controls whether the diagnostic is shown as part of the script&#039;s output.
   This should always be disabled in a production environment, as it can include
   confidential information such as database passwords, but is often useful to
   enable in development, as it ensures immediate reporting of issues.
  </p>

  <p class="simpara">
   In addition to displaying errors, PHP can log diagnostics when the
   <a href="errorfunc.configuration.php#ini.log-errors" class="link"><code class="parameter">log_errors</code></a>
   directive is enabled. This will log any diagnostic to the file or syslog
   defined by
   <a href="errorfunc.configuration.php#ini.error-log" class="link"><code class="parameter">error_log</code></a>.
   This can be extremely useful in a production environment, as diagnostics are
   logged when they occur and can then generate reports based on those logs.
  </p>
  <p class="simpara">
   Individual diagnostics can be suppressed using the
   <code class="literal">@</code> operator.
  </p>

  <div class="warning"><strong class="warning">Aviso</strong>
   <p class="simpara">
    Prior to PHP 8.0.0 it was possible to suppress critical diagnostics that
    would terminate the execution of the PHP script.
   </p>
  </div>

  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="simpara">
    Diagnostics can be added, removed, have their severity altered or be
    elevated to a <span class="exceptionname"><a href="class.throwable.php" class="exceptionname">Throwable</a></span> error in between PHP versions.
   </p>
  </p></blockquote>

  <div class="sect2" id="language.error-handling.diagnostic.user">
   <h3 class="title">User defined diagnostic handler</h3>

   <p class="simpara">
    If PHP&#039;s default diagnostic handling is inadequate,
    it is possible to override the default diagnostic handler with a custom one
    which is set using <span class="function"><a href="function.set-error-handler.php" class="function">set_error_handler()</a></span>.
    Some diagnostics, such as <strong><code><a href="errorfunc.constants.php#constant.e-error">E_ERROR</a></code></strong> and
    <strong><code><a href="errorfunc.constants.php#constant.e-parse">E_PARSE</a></code></strong>, cannot be handled this way (see
    <span class="function"><a href="function.set-error-handler.php" class="function">set_error_handler()</a></span> for the full list).
    The others can be handled in various ways. For example, this can be used to show a custom
    error page to the user and then report more directly than via a log, such
    as by sending an e-mail.
   </p>

   <p class="simpara">
    Another typical usage is to elevate diagnostic errors to exceptions with
    <a href="class.errorexception.php" class="link">ErrorException</a>.
   </p>
   <div class="example" id="example-1">
    <p><strong>Exemplo #1 Elevating diagnostic errors to exceptions</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">function </span><span style="color: #0000BB">exceptions_error_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$severity</span><span style="color: #007700">, </span><span style="color: #0000BB">$message</span><span style="color: #007700">, </span><span style="color: #0000BB">$filename</span><span style="color: #007700">, </span><span style="color: #0000BB">$lineno</span><span style="color: #007700">) {
    if (</span><span style="color: #0000BB">error_reporting</span><span style="color: #007700">() &amp; </span><span style="color: #0000BB">$severity</span><span style="color: #007700">) {
       throw new </span><span style="color: #0000BB">ErrorException</span><span style="color: #007700">(</span><span style="color: #0000BB">$message</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$severity</span><span style="color: #007700">, </span><span style="color: #0000BB">$filename</span><span style="color: #007700">, </span><span style="color: #0000BB">$lineno</span><span style="color: #007700">);
    }
}

</span><span style="color: #0000BB">set_error_handler</span><span style="color: #007700">(</span><span style="color: #DD0000">'exceptions_error_handler'</span><span style="color: #007700">);</span></code></pre></div>
    </div>

    <blockquote class="note"><p><strong class="note">Nota</strong>: 
     <p class="simpara">
      It is important to verify that the severity is included in the current
      list of reportable diagnostics, otherwise the
      <code class="literal">@</code> operator
      will be broken, as an exception will be thrown for a suppressed diagnostic.
      
     </p>
    </p></blockquote>
   </div>
  </div>

  <div class="sect2">
   <h3 class="title">Registro de Alterações</h3>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versão</th>
       <th>Descrição</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.5.0</td>
       <td>
        Fatal errors (such as an exceeded maximum execution time) now include
        a stack trace in their error message.
       </td>
      </tr>

     </tbody>
    
   </table>

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