PHP Error Functions

Beginner
3 min read
Updated: Nov 2026
14 function guides
Function index

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().

Beginner path.

Start with error_reporting() and trigger_error()—then learn set_error_handler() and error_get_last() for handling and debugging.

Good to know.

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:

PHP
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 functions

Choose which levels to report, send messages to a log, and raise your own errors. user_error() is an alias of trigger_error().

FunctionDescriptionTutorial
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 functions

Read or reset the most recent error recorded by PHP.

FunctionDescriptionTutorial
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 functions

Register, restore, and read the callback that handles non-fatal errors. get_error_handler() needs PHP 8.5+.

FunctionDescriptionTutorial
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 functions

Register, restore, and read the callback for uncaught exceptions. get_exception_handler() needs PHP 8.5+.

FunctionDescriptionTutorial
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 functions

Inspect or print the call stack to see how your code reached a point.

FunctionDescriptionTutorial
debug_backtrace()Return the call stack as an array.Try it
debug_print_backtrace()Print the call stack.Try it

Frequently Asked Questions

They are built-in functions for error handling: choose which levels to report, raise and log errors, read the last error, register or restore error and exception handlers, and inspect the call stack with a backtrace.
The Error Handling page teaches the ideas: levels, handlers, the last error, and logging. This index lists every function tutorial so you can open error_reporting(), set_error_handler(), debug_backtrace(), and the rest.
Start with error_reporting() and trigger_error(). Then learn set_error_handler() and restore_error_handler(). Add error_get_last(), error_log(), and debug_backtrace() when you need to debug or log problems.
None. user_error() is an alias of trigger_error(). Both raise a user-level error such as E_USER_WARNING that a handler from set_error_handler() can catch.
No. They need PHP 8.5 or newer. On older versions, keep the return value of set_error_handler() or set_exception_handler(), which gives you the previously registered handler.
If you are new, read PHP Error Handling first. Then open error_reporting(), trigger_error(), and set_error_handler() from the tables below.

Start with debug_backtrace()

Open the first guide—syntax, examples, and FAQs.

debug_backtrace() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful