📄 function.set-error-handler.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Sets a user-defined error handler function</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="function.restore-exception-handler.html">restore_exception_handler</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.set-exception-handler.html">set_exception_handler</a></div> <div class="up"><a href="ref.errorfunc.html">Error Handling Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.set-error-handler" class="refentry"> <div class="refnamediv"> <h1 class="refname">set_error_handler</h1> <p class="verinfo">(PHP 4 >= 4.0.1, PHP 5)</p><p class="refpurpose"><span class="refname">set_error_handler</span> — <span class="dc-title">Sets a user-defined error handler function</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>set_error_handler</b></b></span> ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.callback" class="type callback">callback</a></span> <tt class="parameter">$error_handler</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$error_types</tt></span> ] )</div> <p class="para rdfs-comment"> Sets a user function (<i><tt class="parameter">error_handler</tt></i>) to handle errors in a script. </p> <p class="para"> This function can be used for defining your own way of handling errors during runtime, for example in applications in which you need to do cleanup of data/files when a critical error happens, or when you need to trigger an error under certain conditions (using <a href="function.trigger-error.html" class="function">trigger_error()</a>). </p> <p class="para"> It is important to remember that the standard PHP error handler is completely bypassed. <a href="function.error-reporting.html" class="function">error_reporting()</a> settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of <a href="errorfunc.configuration.html#ini.error-reporting" class="link">error_reporting</a> and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the <a href="language.operators.errorcontrol.html" class="link">@ error-control operator</a>. </p> <p class="para"> Also note that it is your responsibility to <a href="function.die.html" class="function">die()</a> if necessary. If the error-handler function returns, script execution will continue with the next statement after the one that caused an error. </p> <p class="para"> The following error types cannot be handled with a user defined function: <b><tt>E_ERROR</tt></b>, <b><tt>E_PARSE</tt></b>, <b><tt>E_CORE_ERROR</tt></b>, <b><tt>E_CORE_WARNING</tt></b>, <b><tt>E_COMPILE_ERROR</tt></b>, <b><tt>E_COMPILE_WARNING</tt></b>, and most of <b><tt>E_STRICT</tt></b> raised in the file where <b>set_error_handler()</b> is called. </p> <p class="para"> If errors occur before the script is executed (e.g. on file uploads) the custom error handler cannot be called since it is not registered at that time. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">error_handler</tt></i></span> <dd> <p class="para"> The user function needs to accept two parameters: the error code, and a string describing the error. Then there are three optional parameters that may be supplied: the filename in which the error occurred, the line number in which the error occurred, and the context in which the error occurred (an array that points to the active symbol table at the point the error occurred). The function can be shown as: </p> <p class="para"> <div class="methodsynopsis dc-description"> <span class="methodname"><b><span class="replaceable">handler</span></b></span> ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$errno</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$errstr</tt></span> [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$errfile</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$errline</tt></span> [, <span class="methodparam"><span class="type">array</span> <tt class="parameter">$errcontext</tt></span> ]]] )</div> <dl> <dt> <span class="term"><i><tt class="parameter">errno</tt></i></span> <dd> <span class="simpara"> The first parameter, <i><tt class="parameter">errno</tt></i>, contains the level of the error raised, as an integer. </span> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">errstr</tt></i></span> <dd> <span class="simpara"> The second parameter, <i><tt class="parameter">errstr</tt></i>, contains the error message, as a string. </span> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">errfile</tt></i></span> <dd> <span class="simpara"> The third parameter is optional, <i><tt class="parameter">errfile</tt></i>, which contains the filename that the error was raised in, as a string. </span> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">errline</tt></i></span> <dd> <span class="simpara"> The fourth parameter is optional, <i><tt class="parameter">errline</tt></i>, which contains the line number the error was raised at, as an integer. </span> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">errcontext</tt></i></span> <dd> <span class="simpara"> The fifth parameter is optional, <i><tt class="parameter">errcontext</tt></i>, which is an array that points to the active symbol table at the point the error occurred. In other words, <i><tt class="parameter">errcontext</tt></i> will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context. </span> </dd> </dt>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -