PHP Error Functions

About This Index
This page is the PHP Error Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn how errors, handlers, logging, and backtraces fit together on /php/error. Use this page when you need a specific function such as error_reporting(), set_error_handler(), or debug_backtrace().
Start with error_reporting() and trigger_error()—then learn set_error_handler() and error_get_last() for handling and debugging.
user_error() is an alias of trigger_error(). get_error_handler() and get_exception_handler() need PHP 8.5+.
How to Call a PHP Error Function
Error helpers are global functions—call them directly, no object needed:
error_reporting(E_ALL);
set_error_handler(function ($errno, $errstr) {
echo "Error: $errstr";
return true;
});
trigger_error("Something happened", E_USER_NOTICE);
restore_error_handler();
print_r(error_get_last());
error_log("Saved to the log"); PHP Error Functions Table
All function guides in this PHP tutorial series (14 tutorials in 5 categories).
Reporting & logging
4 functionsChoose which levels to report, send messages to a log, and raise your own errors. user_error() is an alias of trigger_error().
| Function | Description | Tutorial |
|---|---|---|
error_reporting() | Set which PHP errors are reported. | Try it |
error_log() | Send an error message to a log, file, or email. | Try it |
trigger_error() | Generate a user-level error, warning, or notice. | Try it |
user_error() | Alias of trigger_error(). | Try it |
Last error
2 functionsRead or reset the most recent error recorded by PHP.
| Function | Description | Tutorial |
|---|---|---|
error_get_last() | Get the last error as an array, or null. | Try it |
error_clear_last() | Clear the most recent error. | Try it |
Error handlers
3 functionsRegister, restore, and read the callback that handles non-fatal errors. get_error_handler() needs PHP 8.5+.
| Function | Description | Tutorial |
|---|---|---|
set_error_handler() | Set a user-defined error handler function. | Try it |
restore_error_handler() | Restore the previous error handler. | Try it |
get_error_handler() | Get the current error handler callback (PHP 8.5+). | Try it |
Exception handlers
3 functionsRegister, restore, and read the callback for uncaught exceptions. get_exception_handler() needs PHP 8.5+.
| Function | Description | Tutorial |
|---|---|---|
set_exception_handler() | Set a user-defined exception handler function. | Try it |
restore_exception_handler() | Restore the previous exception handler. | Try it |
get_exception_handler() | Get the current exception handler callback (PHP 8.5+). | Try it |
Backtrace
2 functionsInspect or print the call stack to see how your code reached a point.
| Function | Description | Tutorial |
|---|---|---|
debug_backtrace() | Return the call stack as an array. | Try it |
debug_print_backtrace() | Print the call stack. | Try it |
Frequently Asked Questions
Start with debug_backtrace()
Open the first guide—syntax, examples, and FAQs.
6 people found this page helpful
