1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-24 07:02:15 +01:00
Files
archived-doc-zh/reference/errorfunc/functions/error-reporting.xml
2023-12-13 02:05:38 +08:00

164 lines
4.8 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 9caac4c5cce859b4ae5d497972442fcfaa840d81 Maintainer: daijie Status: ready -->
<!-- CREDITS: Luffy, mowangjuanzi -->
<refentry xml:id="function.error-reporting" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>error_reporting</refname>
<refpurpose>设置应该报告何种 PHP 错误</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>error_reporting</methodname>
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>error_level</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<para>
<function>error_reporting</function> 函数能够在运行时设置 <link linkend="ini.error-reporting">error_reporting</link> 指令。
PHP 有诸多错误级别,使用该函数可以设置在脚本运行时的级别。
如果没有设置可选参数 <parameter>error_level</parameter>
<function>error_reporting</function> 仅会返回当前的错误报告级别。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>error_level</parameter></term>
<listitem>
<para>
新的 <link linkend="ini.error-reporting">error_reporting</link> 级别。
可以是一个位掩码也可以是一个已命名的常量。
强烈建议使用已命名的常量,以确保兼容将来的版本。
由于错误级别的添加、整数取值范围的增加,
较久的基于整数的错误级别不会总是和预期的表现一致。
</para>
<para>
可用的错误级别常量及其实际含义描述在了
<link linkend="errorfunc.constants">predefined constants</link> 中。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
在更改为 <parameter>error_level</parameter> <emphasis>之前</emphasis>返回 <link linkend="ini.error-reporting">error_reporting</link> 级别。
</para>
<note>
<simpara>
<link linkend="language.operators.errorcontrol">错误控制</link> <literal>@</literal> 运算符在错误处理期间会更改错误级别。
</simpara>
</note>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>error_level</parameter> 现在可以为空。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>error_reporting</function> 范例</title>
<programlisting role="php">
<![CDATA[
<?php
// 关闭所有PHP错误报告
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// 报告 E_NOTICE也挺好 (报告未初始化的变量
// 或者捕获变量名的错误拼写)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// 除了 E_NOTICE报告其他所有错误
error_reporting(E_ALL ^ E_NOTICE);
// 报告所有 PHP 错误
error_reporting(E_ALL);
// 报告所有 PHP 错误
error_reporting(-1);
// 和 error_reporting(E_ALL); 一样
ini_set('error_reporting', E_ALL);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<tip>
<simpara>
传入 <literal>-1</literal> 的值将尽可能显示所有错误,甚至包括将来 PHP
可能加入的新的错误级别和常量。常量 <constant>E_ALL</constant> 有同样的行为。
</simpara>
</tip>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><link linkend="ini.display-errors">display_errors</link> 指令</member>
<member><link linkend="ini.html-errors">html_errors</link> 指令</member>
<member><link linkend="ini.xmlrpc-errors">xmlrpc_errors</link> 指令</member>
<member><link linkend="language.operators.errorcontrol">错误控制</link>运算符</member>
<member><function>ini_set</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->