<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >错误控制运算符</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="运算符" HREF="language.operators.html"><LINK REL="PREVIOUS" TITLE="比较运算符" HREF="language.operators.comparison.html"><LINK REL="NEXT" TITLE="执行运算符" HREF="language.operators.execution.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="language.operators.comparison.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >章 15. 运算符</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="language.operators.execution.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="language.operators.errorcontrol" >错误控制运算符</A ></H1 ><P > PHP 支持一个错误控制运算符:@。当将其放置在一个 PHP 表达式之前,该表达式可能产生的任何错误信息都被忽略掉。 </P ><P > 如果激活了 <A HREF="ref.errorfunc.html#ini.track-errors" ><CODE CLASS="option" >track_errors</CODE ></A > 特性,表达式所产生的任何错误信息都被存放在变量 <A HREF="reserved.variables.html#reserved.variables.phperrormsg" >$php_errormsg</A > 中。此变量在每次出错时都会被覆盖,所以如果想用它的话就要尽早检查。 </P ><P > <DIV CLASS="informalexample" ><P ></P ><A NAME="AEN4427" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Intentional file error */<br /></font><font color="#0000BB">$my_file </font><font color="#007700">= @</font><font color="#0000BB">file </font><font color="#007700">(</font><font color="#DD0000">'non_existent_file'</font><font color="#007700">) or<br /> die (</font><font color="#DD0000">"Failed opening file: error was '$php_errormsg'"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// this works for any expression, not just functions:<br /></font><font color="#0000BB">$value </font><font color="#007700">= @</font><font color="#0000BB">$cache</font><font color="#007700">[</font><font color="#0000BB">$key</font><font color="#007700">];<br /></font><font color="#FF8000">// will not issue a notice if the index $key doesn't exist.<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > @ 运算符只对<A HREF="language.expressions.html" >表达式</A >有效。对新手来说一个简单的规则就是:如果能从某处得到值,就能在它前面加上 @ 运算符。例如,可以把它放在变量,函数和 <A HREF="function.include.html" ><B CLASS="function" >include()</B ></A > 调用,常量,等等之前。不能把它放在函数或类的定义之前,也不能用于条件结构例如 <TT CLASS="literal" >if</TT > 和 <TT CLASS="literal" >foreach</TT > 等。 </P ></BLOCKQUOTE ></DIV ><P > 参见 <A HREF="function.error-reporting.html" ><B CLASS="function" >error_reporting()</B ></A > 及手册中<A HREF="ref.errorfunc.html" >错误处理及日志函数</A >的有关章节。 </P ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >警告</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > 目前的“@”错误控制运算符前缀甚至使导致脚本终止的严重错误的错误报告也失效。这意味着如果在某个不存在或类型错误的函数调用前用了“@”来抑制错误信息,那脚本会没有任何迹象显示原因而死在那里。 </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="language.operators.comparison.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="language.operators.execution.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >比较运算符</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="language.operators.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >执行运算符</TD ></TR ></TABLE ></DIV ></BODY ></HTML >