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
 |
 |
 |
 |
|
The Ektron Intranet
lets you do everything you need to do on your corporate intranet and everything you want to do... all with just one application.
What can you do with the Ektron Intranet? |
 |
Navigate through content, documents, assets, colleagues and workgroups quickly and intuitively with enterprise search |
 |
Communicate with friends and colleagues with forums, message boards and corporate blogging using the new Social Networking Platform |

|
Utilize the extensive out-of-the box features or customize your site through Ektron CMS400.NET's open architecture |
 |
Promote collaboration in your organization through project workspaces where others can efficiently find information and work together |
 |
Author/edit content, manage navigation, menus, audit trails, workflow and approvals with the best in breed Content Management |
|
|
|
|
See why there are 20,000+ Ektron integrations worldwide.
|
|
 |
TAKE THE VIDEO TOUR |
 |
or download a FREE TRIAL today. |
|