📄 language.operators.errorcontrol.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Error Control Operators</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.operators.comparison.html">Comparison Operators</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.operators.execution.html">Execution Operators</a></div> <div class="up"><a href="language.operators.html">Operators</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><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.html#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.html" 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"> <div class="informalexample"> <div class="example-contents"><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 '$php_errormsg'"</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> <blockquote><p><b class="note">Note</b>: <span class="simpara"> The @-operator works only on <a href="language.expressions.html" 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 <b>include()</b> calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as <i>if</i> and <i>foreach</i>, and so forth. </span> </p></blockquote> <p class="simpara"> See also <a href="function.error-reporting.html" class="function">error_reporting()</a> and the manual section for <a href="ref.errorfunc.html" 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><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="language.operators.comparison.html">Comparison Operators</a></div> <div class="next" style="text-align: right; float: right;"><a href="language.operators.execution.html">Execution Operators</a></div> <div class="up"><a href="language.operators.html">Operators</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -