<HTML ><HEAD ><TITLE >Error Handling and Logging Functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="dotnet_load" HREF="function.dotnet-load.html"><LINK REL="NEXT" TITLE="debug_backtrace" HREF="function.debug-backtrace.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="reference" 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 Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.dotnet-load.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.debug-backtrace.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.errorfunc" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >XXVII. Error Handling and Logging Functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN22477" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="errorfunc.intro" ></A >Introduction</H1 ><P > These are functions dealing with error handling and logging. They allow you to define your own error handling rules, as well as modify the way the errors can be logged. This allows you to change and enhance error reporting to suit your needs. </P ><P > With the logging functions, you can send messages directly to other machines, to an email (or email to pager gateway!), to system logs, etc., so you can selectively log and monitor the most important parts of your applications and websites. </P ><P > The error reporting functions allow you to customize what level and kind of error feedback is given, ranging from simple notices to customized functions returned during errors. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="errorfunc.requirements" ></A >Requirements</H1 ><P >No external libraries are needed to build this extension.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="errorfunc.installation" ></A >Installation</H1 ><P >There is no installation needed to use these functions; they are part of the PHP core.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="errorfunc.configuration" ></A >Runtime Configuration</H1 ><P > The behaviour of these functions is affected by settings in <TT CLASS="filename" >php.ini</TT >. </P ><P > <DIV CLASS="table" ><A NAME="AEN22494" ></A ><P ><B >Table 1. Errors and Logging Configuration Options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Name</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Default</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Changeable</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >error_reporting</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >E_ALL & ~E_NOTICE</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >display_errors</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >display_startup_errors</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >log_errors</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >log_errors_max_len</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"1024"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >ignore_repeated_errors</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >ignore_repeated_source</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >report_memleaks</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_SYSTEM</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >track_errors</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"0"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >html_errors</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"1"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >docref_root</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >"http://www.php.net/"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >docref_ext</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >".html"</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >error_prepend_string</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >NULL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >error_append_string</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >NULL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >error_log</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >NULL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI_ALL</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >warn_plus_overloading</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >NULL</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP_INI??</TD ></TR ></TBODY ></TABLE ></DIV > For further details and definition of the PHP_INI_* constants see <A HREF="function.ini-set.html" ><B CLASS="function" >ini_set()</B ></A >. </P ><P > Here is a short explanation of the configuration directives. <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.error-reporting" ></A ><TT CLASS="parameter" ><I >error_reporting</I ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Set the error reporting level. The parameter is either an integer representing a bit field, or named constants. The error_reporting levels and constants are described in <A HREF="ref.errorfunc.html#errorfunc.constants" >Predefined Constants</A >, and in <TT CLASS="filename" >php.ini</TT >. To set at runtime, use the <A HREF="function.error-reporting.html" ><B CLASS="function" >error_reporting()</B ></A > function. See also the <A HREF="ref.errorfunc.html#ini.display-errors" >display_errors</A > directive. </P ><P > In PHP 4 the default value does not show <TT CLASS="constant" ><B >E_NOTICE</B ></TT > level errors. You may want to show them during development. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B >Enabling <TT CLASS="constant" ><B >E_NOTICE</B ></TT > during development has some benefits. For debugging purposes: NOTICE messages will warn you about possibls bugs in your code. For example, use of unassigned values are warned. It is extremely useful to find typos and to save time for debugging. NOTICE messages will warn you about bad style. For example, $arr[item] is better to be written as $arr['item'] since PHP tries to treat "item" as constant. If it is not a constant, PHP assumes it is a string index for the array. </P ></BLOCKQUOTE ></DIV ><P > In PHP 3, the default setting is <TT CLASS="literal" >(E_ERROR | E_WARNING | E_PARSE)</TT >, meaning the same thing. Note, however, that since constants are not supported in PHP 3's <TT CLASS="filename" >php3.ini</TT >, the error_reporting setting there must be numeric; hence, it is <TT CLASS="literal" >7</TT >. </P ></DD ><DT ><A NAME="ini.display-errors" ></A ><TT CLASS="parameter" ><I >display_errors</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > This determines whether errors should be printed to the screen as part of the HTML output or not. </P ></DD ><DT ><A NAME="ini.display-startup-errors" ></A ><TT CLASS="parameter" ><I >display_startup_errors</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed. It's strongly recommended to keep display_startup_errors off, except for debugging. </P ></DD ><DT ><A NAME="ini.log-errors" ></A ><TT CLASS="parameter" ><I >log_errors</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > Tells whether script error messages should be logged to the server's error log or <A HREF="ref.errorfunc.html#ini.error-log" >error_log</A >. This option is thus server-specific. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > You're strongly advised to use error logging in place of error displaying on production web sites. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.log-errors-max-len" ></A ><TT CLASS="parameter" ><I >log_errors_max_len</I ></TT > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Set the maximum length of log_errors in kbytes. In <A HREF="ref.errorfunc.html#ini.error-log" >error_log</A > information about the source is added. The default is 1024 and 0 allows to not apply any maximum length at all. </P ></DD ><DT ><A NAME="ini.ignore-repeated-errors" ></A ><TT CLASS="parameter" ><I >ignore_repeated_errors</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > Do not log repeated messages. Repeated errors must occur in the same file on the same line until <A HREF="ref.errorfunc.html#ini.ignore-repeated-source" >ignore_repeated_source</A > is set true. </P ></DD ><DT ><A NAME="ini.ignore-repeated-source" ></A ><TT CLASS="parameter" ><I >ignore_repeated_source</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > Ignore source of message when ignoring repeated messages. When this setting is On you will not log errors with repeated messages from different files or sourcelines. </P ></DD ><DT ><A NAME="ini.report-memleaks" ></A ><TT CLASS="parameter" ><I >report_memleaks</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > If this parameter is set to Off, then memory leaks will not be shown (on stdout or in the log). This has only effect in a debug compile, and if <A HREF="ref.errorfunc.html#ini.error-reporting" >error_reporting</A > includes E_WARNING in the allowed list </P ></DD ><DT ><A NAME="ini.track-errors" ></A ><TT CLASS="parameter" ><I >track_errors</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > If enabled, the last error message will always be present in the variable <A HREF="reserved.variables.html#reserved.variables.phperrormsg" >$php_errormsg</A >. </P ></DD ><DT ><A NAME="ini.html-errors" ></A ><TT CLASS="parameter" ><I >html_errors</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > Turn off HTML tags in error messages. The new format for html errors produces clickable messages that direct the user to a page describing the error or function in causing the error. These references are affected by <A HREF="ref.errorfunc.html#ini.docref-root" >docref_root</A > and <A HREF="ref.errorfunc.html#ini.docref-ext" >docref_ext</A >. </P ></DD ><DT ><A NAME="ini.docref-root" ></A ><TT CLASS="parameter" ><I >docref_root</I ></TT > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > The new error format contains a reference to a page describing the error or function in causing the error. In case of manual pages you can download the manual in your language and set this ini directive to the url of your local copy. If your local copy of the manual can be reached by '/manual/' you can simply use <TT CLASS="userinput" ><B >docref_root=/manual/</B ></TT >. Additional you have to set docref_ext to match the fileextensions of your copy <TT CLASS="userinput" ><B >docref_ext=.html</B ></TT >. It is possible to use external references. For example you can use <TT CLASS="userinput" ><B >docref_root=http://manual/en/</B ></TT > or <TT CLASS="userinput" ><B >docref_root="http://landonize.it/?how=url&theme=classic&filter=Landon&url=http%3A%2F%2Fwww.php.net%2F"</B ></TT > </P ><P > Most of the time you want the docref_root value to end with a slash '/'. But see the second example above which does not have nor need it. </P ></DD ><DT ><A NAME="ini.docref-ext" ></A ><TT CLASS="parameter" ><I >docref_ext</I ></TT > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > See <A HREF="ref.errorfunc.html#ini.docref-root" >docref_root</A >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The value of docref_ext must begin with a dot '.'. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><A NAME="ini.error-prepend-string" ></A ><TT CLASS="parameter" ><I >error_prepend_string</I ></TT > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > String to output before an error message. </P ></DD ><DT ><A NAME="ini.error-append-string" ></A ><TT CLASS="parameter" ><I >error_append_string</I ></TT > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > String to output after an error message. </P ></DD ><DT ><A NAME="ini.error-log" ></A ><TT CLASS="parameter" ><I >error_log</I ></TT > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > Name of the file where script errors should be logged. If the special value <TT CLASS="literal" >syslog</TT > is used, the errors are sent to the system logger instead. On UNIX, this means syslog(3) and on Windows NT it means the event log. The system logger is not supported on Windows 95. See also: <A HREF="function.syslog.html" ><B CLASS="function" >syslog()</B ></A >. </P ></DD ><DT ><A NAME="ini.warn-plus-overloading" ></A ><TT CLASS="parameter" ><I >warn_plus_overloading</I ></TT > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > If enabled, this option makes PHP output a warning when the plus (<TT CLASS="literal" >+</TT >) operator is used on strings. This is to make it easier to find scripts that need to be rewritten to using the string concatenator instead (<TT CLASS="literal" >.</TT >). </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="errorfunc.constants" ></A >Predefined Constants</H1 ><P > The constants below are always available as part of the PHP core. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > You may use these constant names in <TT CLASS="filename" >php.ini</TT > but not outside of PHP, like in <TT CLASS="filename" >httpd.conf</TT >, where you'd use the bitmask values instead. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="table" ><A NAME="AEN22707" ></A ><P ><B >Table 2. Errors and Logging</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Value</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Constant</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Description</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Note</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >1</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_ERROR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >2</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_WARNING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Run-time warnings (non-fatal errors). Execution of the script is not halted. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >4</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_PARSE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Compile-time parse errors. Parse errors should only be generated by the parser. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >8</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_NOTICE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >16</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_CORE_ERROR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Fatal errors that occur during PHP's initial startup. This is like an <TT CLASS="constant" ><B >E_ERROR</B ></TT >, except it is generated by the core of PHP. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP 4 only</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >32</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_CORE_WARNING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an <TT CLASS="constant" ><B >E_WARNING</B ></TT >, except it is generated by the core of PHP. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP 4 only</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >64</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_COMPILE_ERROR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Fatal compile-time errors. This is like an <TT CLASS="constant" ><B >E_ERROR</B ></TT >, except it is generated by the Zend Scripting Engine. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP 4 only</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >128</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_COMPILE_WARNING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > Compile-time warnings (non-fatal errors). This is like an <TT CLASS="constant" ><B >E_WARNING</B ></TT >, except it is generated by the Zend Scripting Engine. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP 4 only</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >256</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_USER_ERROR</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > User-generated error message. This is like an <TT CLASS="constant" ><B >E_ERROR</B ></TT >, except it is generated in PHP code by using the PHP function <A HREF="function.trigger-error.html" ><B CLASS="function" >trigger_error()</B ></A >. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP 4 only</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >512</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_USER_WARNING</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > User-generated warning message. This is like an <TT CLASS="constant" ><B >E_WARNING</B ></TT >, except it is generated in PHP code by using the PHP function <A HREF="function.trigger-error.html" ><B CLASS="function" >trigger_error()</B ></A >. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP 4 only</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >1024</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_USER_NOTICE</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > User-generated notice message. This is like an <TT CLASS="constant" ><B >E_NOTICE</B ></TT >, except it is generated in PHP code by using the PHP function <A HREF="function.trigger-error.html" ><B CLASS="function" >trigger_error()</B ></A >. </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PHP 4 only</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >2047</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > <TT CLASS="constant" ><B >E_ALL</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" > All errors and warnings, as supported. </TD ><TD > </TD ></TR ></TBODY ></TABLE ></DIV ><P > The above values (either numerical or symbolic) are used to build up a bitmask that specifies which errors to report. You can use the <A HREF="language.operators.bitwise.html" >bitwise operators</A > to combine these values or mask out certain types of errors. Note that only '|', '~', '!', and '&' will be understood within <TT CLASS="filename" >php.ini</TT >, however, and that no bitwise operators will be understood within <TT CLASS="filename" >php3.ini</TT >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="errorfunc.examples" ></A >Examples</H1 ><P > Below we can see an example of using the error handling capabilities in PHP. We define a error handling function which logs the information into a file (using an XML format), and e-mails the developer in case a critical error in the logic happens. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN22817" ></A ><P ><B >Example 1. Using error handling in a script</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php // we will do our own error handling error_reporting(0); // user defined error handling function function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) { // timestamp for the error entry $dt = date("Y-m-d H:i:s (T)"); // define an assoc array of error string // in reality the only entries we should // consider are 2,8,256,512 and 1024 $errortype = array ( 1 => "Error", 2 => "Warning", 4 => "Parsing Error", 8 => "Notice", 16 => "Core Error", 32 => "Core Warning", 64 => "Compile Error", 128 => "Compile Warning", 256 => "User Error", 512 => "User Warning", 1024=> "User Notice" ); // set of errors for which a var trace will be saved $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE); $err = "<errorentry>\n"; $err .= "\t<datetime>".$dt."</datetime>\n"; $err .= "\t<errornum>".$errno."</errornum>\n"; $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n"; $err .= "\t<errormsg>".$errmsg."</errormsg>\n"; $err .= "\t<scriptname>".$filename."</scriptname>\n"; $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n"; if (in_array($errno, $user_errors)) $err .= "\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n"; $err .= "</errorentry>\n\n"; // for testing // echo $err; // save to the error log, and e-mail me if there is a critical user error error_log($err, 3, "/usr/local/php4/error.log"); if ($errno == E_USER_ERROR) mail("phpdev@example.com","Critical User Error",$err); } function distance ($vect1, $vect2) { if (!is_array($vect1) || !is_array($vect2)) { trigger_error("Incorrect parameters, arrays expected", E_USER_ERROR); return NULL; } if (count($vect1) != count($vect2)) { trigger_error("Vectors need to be of the same size", E_USER_ERROR); return NULL; } for ($i=0; $i<count($vect1); $i++) { $c1 = $vect1[$i]; $c2 = $vect2[$i]; $d = 0.0; if (!is_numeric($c1)) { trigger_error("Coordinate $i in vector 1 is not a number, using zero", E_USER_WARNING); $c1 = 0.0; } if (!is_numeric($c2)) { trigger_error("Coordinate $i in vector 2 is not a number, using zero", E_USER_WARNING); $c2 = 0.0; } $d += $c2*$c2 - $c1*$c1; } return sqrt($d); } $old_error_handler = set_error_handler("userErrorHandler"); // undefined constant, generates a warning $t = I_AM_NOT_DEFINED; // define some "vectors" $a = array(2,3,"foo"); $b = array(5.5, 4.3, -1.6); $c = array (1,-3); // generate a user error $t1 = distance($c,$b)."\n"; // generate another user error $t2 = distance($b,"i am not an array")."\n"; // generate a warning $t3 = distance($a,$b)."\n"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="errorfunc.seealso" ></A >See Also</H1 ><P > See also <A HREF="function.syslog.html" ><B CLASS="function" >syslog()</B ></A >. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.debug-backtrace.html" >debug_backtrace</A > -- Generates a backtrace </DT ><DT ><A HREF="function.error-log.html" >error_log</A > -- send an error message somewhere</DT ><DT ><A HREF="function.error-reporting.html" >error_reporting</A > -- set which PHP errors are reported</DT ><DT ><A HREF="function.restore-error-handler.html" >restore_error_handler</A > -- Restores the previous error handler function </DT ><DT ><A HREF="function.set-error-handler.html" >set_error_handler</A > -- Sets a user-defined error handler function. </DT ><DT ><A HREF="function.trigger-error.html" >trigger_error</A > -- Generates a user-level error/warning/notice message </DT ><DT ><A HREF="function.user-error.html" >user_error</A > -- Generates a user-level error/warning/notice message </DT ></DL ></DIV ></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="function.dotnet-load.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.debug-backtrace.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >dotnet_load</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >debug_backtrace</TD ></TR ></TABLE ></DIV ></BODY ></HTML >