<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.operators.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'language.operators.errorcontrol.php',
    1 => 'Error Control',
    2 => 'Error Control Operators',
  ),
  'up' => 
  array (
    0 => 'language.operators.php',
    1 => 'Operators',
  ),
  'prev' => 
  array (
    0 => 'language.operators.comparison.php',
    1 => 'Comparison',
  ),
  'next' => 
  array (
    0 => 'language.operators.execution.php',
    1 => 'Execution',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'language/operators/errorcontrol.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.operators.errorcontrol" class="sect1">
 <h2 class="title">Error Control Operators</h2>
 
 <p class="simpara">
  PHP supports one error control operator: the at sign (<code class="literal">@</code>).
  When prepended to an expression in PHP, any diagnostic error that might
  be generated by that expression will be suppressed.
 </p>
 <p class="para">
  If a custom error handler function is set with
  <span class="function"><a href="function.set-error-handler.php" class="function">set_error_handler()</a></span>, it will still be called even though
  the diagnostic has been suppressed.
 </p>

 <div class="warning"><strong class="warning">Увага</strong>
  <p class="para">
   Prior to PHP 8.0.0, the <span class="function"><a href="function.error-reporting.php" class="function">error_reporting()</a></span> called inside the custom error handler
   always returned <code class="literal">0</code> if the error was suppressed by the <code class="literal">@</code> operator.
   As of PHP 8.0.0, it returns the value of this (bitwise) expression:
   <code class="literal">E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE</code>.
  </p>
 </div>

 <p class="simpara">
  Any error message generated by the expression is available in the <code class="literal">&quot;message&quot;</code>
  element of the array returned by <span class="function"><a href="function.error-get-last.php" class="function">error_get_last()</a></span>.
  The result of that function will change on each error, so it needs to be checked early.
 </p>
 <p class="para">
  <div class="example" id="example-1">
   <p><strong>Приклад #1 Intentional file error</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$my_file </span><span style="color: #007700">= @</span><span style="color: #0000BB">file </span><span style="color: #007700">(</span><span style="color: #DD0000">'non_existent_file'</span><span style="color: #007700">) or<br />    die (</span><span style="color: #DD0000">"Failed opening file: error was '" </span><span style="color: #007700">. </span><span style="color: #0000BB">error_get_last</span><span style="color: #007700">()[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">] . </span><span style="color: #DD0000">"'"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </p>
 <p class="para">
  <div class="example" id="example-2">
   <p><strong>Приклад #2 Suppressing Expressions</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// this works for any expression, not just functions:<br /></span><span style="color: #0000BB">$value </span><span style="color: #007700">= @</span><span style="color: #0000BB">$cache</span><span style="color: #007700">[</span><span style="color: #0000BB">$key</span><span style="color: #007700">];<br /></span><span style="color: #FF8000">// will not issue a notice if the index $key doesn't exist.<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </p>
 <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
  <span class="simpara">
   The <code class="literal">@</code>-operator works only on
   <a href="language.expressions.php" class="link">expressions</a>.
   A simple rule of thumb is: if one can take the value of something,
   then one can prepend the <code class="literal">@</code> operator to it.
   For instance, it can be prepended to variables, functions calls,
   certain language construct calls (e.g. <span class="function"><a href="function.include.php" class="function">include</a></span>),
   and so forth.
   It cannot be prepended to function or class definitions,
   or conditional structures such as <code class="literal">if</code> and
   <a href="control-structures.foreach.php" class="link">foreach</a>, and so forth.
  </span>
 </p></blockquote>
 <div class="warning"><strong class="warning">Увага</strong>
  <p class="para">
   Prior to PHP 8.0.0, it was possible for the <code class="literal">@</code> operator
   to disable critical errors that will terminate script execution.
   For example, prepending <code class="literal">@</code> to a call of a function
   which did not exist, by being unavailable or mistyped, would cause
   the script to terminate with no indication as to why.
  </p>
 </div>

 <div class="sect2">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.error-reporting.php" class="function">error_reporting()</a></span></li>
    <li><a href="ref.errorfunc.php" class="link">Error Handling and Logging functions</a></li>
   </ul>
  </p>
 </div>
</div><?php manual_footer($setup); ?>