PHP set_error_handler() Function
Complete PHP Error Reference
Definition and Usage
The set_error_handler() function sets a user-defined function to handle
errors.
This function is used to create your own way of handling errors during
runtime.
This function returns the old error handler, or NULL on failure.
Syntax
|
set_error_handler(error_function,error_types)
|
| Parameter |
Description |
| error_function |
Required. Specifies the function to be run at errors |
| error_types |
Optional. Specifies on which errors report levels the
user-defined error will be shown. Default is "E_ALL". See
table below for possible error report levels |
error_function
Syntax
error_function(error_level,error_message,
error_file,error_line,error_context)
|
| Parameter |
Description |
| error_level |
Required. Specifies the error report level for the
user-defined error. Must be a value number. See table below for possible
error report levels |
| error_message |
Required. Specifies the error message for the user-defined
error |
| error_file |
Optional. Specifies the filename in which the error
occurred |
| error_line |
Optional. Specifies the line number in which the error
occurred |
| error_context |
Optional. Specifies an array that points to the active
symbol table at the point the error occurred. In other words, error_context
will contain an array of every variable that existed in the scope the error
was triggered in |
Error Report levels
| Value |
Constant |
Description |
| 2 |
E_WARNING |
Non-fatal run-time errors. Execution of the script is not
halted |
| 8 |
E_NOTICE |
Run-time notices. The script found something that might be
an error, but could also happen when running a script normally |
| 256 |
E_USER_ERROR |
Fatal user-generated error. This is like an E_ERROR set by
the programmer using the PHP function trigger_error() |
| 512 |
E_USER_WARNING |
Non-fatal user-generated warning. This is like an E_WARNING
set by the programmer using the PHP function trigger_error() |
| 1024 |
E_USER_NOTICE |
User-generated notice. This is like an E_NOTICE set by the
programmer using the PHP function trigger_error() |
| 4096 |
E_RECOVERABLE_ERROR |
Catchable fatal error. This is like an E_ERROR but can be
caught by a user defined handle (see also set_error_handler()) |
| 8191 |
E_ALL |
All errors and warnings, except level E_STRICT (E_STRICT
will be part of E_ALL as of PHP 6.0) |
Tips and Notes
Tip: The standard PHP error handler is completely
bypassed if this function is used, and the user-defined error handler must
terminate the script (die() ) if necessary
Note:
If errors occur before the script is executed the custom
error handler cannot be used since it is not registered at that time
Example
<?php
//error handler function
function customError($errno, $errstr, $errfile, $errline)
{
echo "<b>Custom error:</b> [$errno] $errstr<br />";
echo " Error on line $errline in $errfile<br />";
echo "Ending Script";
die();
}
//set error handler
set_error_handler("customError");
$test=2;
//trigger error
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
?>
|
The output of the code above should be something like this:
Custom error: [1024] A custom error has been triggered
Error on line 19 in C:\webfolder\test.php
Ending Script
|
Complete PHP Error Reference
Make your web applications look like a million bucks
|
|
Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces "life" into the web applications by converting monotonous data into lively charts, gauges & maps.
FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc.
and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise
whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our
12,000 customers and 150,000 users which include a majority of the Fortune 500 companies.
And yeah, your applications could look like a million bucks by spending just $69.
So go ahead, download your
copy of FusionCharts and start "wow-ing" your customers now!
|
 |
W3Schools' Online Certification Program
The perfect solution for professionals who need to balance work, family, and career building.
More than 4000 certificates already issued!
|
The HTML Certificate documents your knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
|