Source of: /manual/en/language.operators.errorcontrol.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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 => 'en',
),
'this' =>
array (
0 => 'language.operators.errorcontrol.php',
1 => 'Error Control Operators',
),
'up' =>
array (
0 => 'language.operators.php',
1 => 'Operators',
),
'prev' =>
array (
0 => 'language.operators.comparison.php',
1 => 'Comparison Operators',
),
'next' =>
array (
0 => 'language.operators.execution.php',
1 => 'Execution Operators',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<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 (@). When
prepended to an expression in PHP, any error messages that might
be generated by that expression will be ignored.
</p>
<p class="simpara">
If the <a href="errorfunc.configuration.php#ini.track-errors" class="link"><span class="option">track_errors</span></a>
feature is enabled, any error message generated by the expression
will be saved in the variable
<var class="varname"><a href="reserved.variables.phperrormsg.php" class="classname">$php_errormsg</a></var>.
This variable will be overwritten on each error, so check early if you
want to use it.
</p>
<p class="para">
</p><div class="informalexample">
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Intentional file error */<br /></span><span style="color: #0000BB">$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: #0000BB">$php_errormsg</span><span style="color: #DD0000">'"</span><span style="color: #007700">);<br /><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 /><br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
The @-operator works only on
<a href="language.expressions.php" class="link">expressions</a>. A simple rule
of thumb is: if you can take the value of something, you can prepend
the @ operator to it. For instance, you can prepend it to variables,
function and <a href="function.include.php" class="function">include()</a> calls, constants, and
so forth. You cannot prepend it to function or class definitions,
or conditional structures such as <i>if</i> and
<a href="control-structures.foreach.php" class="link">foreach</a>, and so forth.
</span>
</p></blockquote>
<p class="simpara">
See also <a href="function.error-reporting.php" class="function">error_reporting()</a> and the manual section for
<a href="ref.errorfunc.php" class="link">Error Handling and Logging functions</a>.
</p>
<div class="warning"><b class="warning">Warning</b>
<p class="para">
Currently the "@" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "@" to
suppress errors from a certain function and either it isn't
available or has been mistyped, the script will die right there
with no indication as to why.
</p>
</div>
</div><?php manual_footer(); ?>