* Made clear this sets error_reporting directive at runtime (like ini_set)

* Removed bitmask example section, constants are preferred.
  Bitmask use is still explained.
* See also: display_errors and ini_set()
* Added a couple more examples.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@88597 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2002-07-13 23:03:09 +00:00
parent 6cdf0cb2f1
commit 307d38d980

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- $Revision: 1.3 $ -->
<!-- splitted from ./en/functions/errorfunc.xml, last change in rev 1.1 -->
<refentry id="function.error-reporting">
<refnamediv>
@ -13,30 +13,62 @@
<methodparam choice="opt"><type>int</type><parameter>level</parameter></methodparam>
</methodsynopsis>
<para>
Sets PHP's error reporting level and returns the old level. The
error reporting level is either a bitmask, or named constant. Using
named constants is strongly encouraged to ensure compatibility for
future versions. As error levels are added, the range of integers
increases, so older integer-based error levels will not always
behave as expected.
The <function>error_reporting</function> function sets the
<link linkend="ini.error-reporting">error_reporting</link>
directive at runtime. PHP has many levels of errors, using
this function sets that level for the duration (runtime) of
your script.
</para>
<para>
<function>error_reporting</function> sets PHP's error reporting level,
and returns the old level. The <parameter>level</parameter> parameter
takes on either a bitmask, or named constants. Using named constants
is strongly encouraged to ensure compatibility for future versions. As
error levels are added, the range of integers increases, so older
integer-based error levels will not always behave as expected.
</para>
<para>
Some example uses:
</para>
<para>
<example role="php">
<title>Error Integer changes</title>
<title><function>error_reporting</function> examples</title>
<programlisting role="php">
<![CDATA[
error_reporting (55); // PHP 3 equivalent to E_ALL ^ E_NOTICE
<?php
/* ...in PHP 4, '55' would mean (E_ERROR | E_WARNING | E_PARSE |
E_CORE_ERROR | E_CORE_WARNING) */
// Turn off all error reporting
error_reporting(0);
error_reporting (2039); // PHP 4 equivalent to E_ALL ^ E_NOTICE
// Report simple running errors
error_reporting (E_ERROR | E_WARNING | E_PARSE);
error_reporting (E_ALL ^ E_NOTICE); // The same in both PHP 3 and 4
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting (E_ALL ^ E_NOTICE);
// Report all PHP errors (bitwise 63 may be used in PHP 3)
error_reporting (E_ALL);
// Same as error_reporting(E_ALL);
ini_set ('error_reporting', E_ALL);
?>
]]>
</programlisting>
</example>
Follow the links of the constants to get their meanings:
</para>
<para>
The available error level constants are listed below. The actual
meanings of these error levels are described in the
<link linkend="features.error-handling">error handling</link>
section of the manual.
<table>
<title><function>error_reporting</function> bit values</title>
<title><function>error_reporting</function> level constants and bit values</title>
<tgroup cols="2">
<thead>
<row>
@ -122,25 +154,8 @@ error_reporting (E_ALL ^ E_NOTICE); // The same in both PHP 3 and 4
</table>
</para>
<para>
<example role="php">
<title><function>error_reporting</function> examples</title>
<programlisting role="php">
<![CDATA[
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting (E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings)
error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all PHP errors (use bitwise 63 in PHP 3)
error_reporting (E_ALL);
]]>
</programlisting>
</example>
See also the <link linkend="ini.display-errors">display_errors</link>
directive and <function>ini_set</function>.
</para>
</refsect1>
</refentry>