PHP | Error Handling Functions

PHP Error Handling Functions


Hello dear readers! welcome back to another edition of our tutorial on PHP. In this tutorial guide, we are going to be discussing about the PHP Error Handling Functions.

PHP error handling functions are the functions dealing with error handling and logging. They allow you to define your own error handling rules, as well as modify the way the errors can be logged. This lets you change and enhance error reporting to suit your needs.

Using these built-in PHP functions, you can send messages directly to other machines, emails, to system logs, etc., so you can selectively log and then monitor the most vital parts of your applications and websites.

Installation

There is no Installation needed to use these functions; they are part of the PHP core.


Runtime Configuration

The behaviour of these functions is affected by settings in php.ini. The following are the definition of these settings -

NameDefaultChangeableChangelog
error_reportingNULLPHP_INI_ALL
display_errors"1"PHP_INI_ALL
display_startup_errors"0"PHP_INI_ALLAvailable since PHP 4.0.3.
log_errors"0"PHP_INI_ALL
log_errors_max_len"1024"PHP_INI_ALLAvailable since PHP 4.3.0.
ignore_repeated_errors"0"PHP_INI_ALLAvailable since PHP 4.3.0.
ignore_repeated_source"0"PHP_INI_ALLAvailable since PHP 4.3.0.
report_memleaks"1"PHP_INI_ALLAvailable since PHP 4.3.0.
track_errors"0"PHP_INI_ALL
html_errors"1"PHP_INI_ALLPHP_INI_SYSTEM in PHP <= 4.2.3. Available since PHP 4.0.2.
docref_root""PHP_INI_ALLAvailable since PHP 4.3.0.
docref_ext""PHP_INI_ALLAvailable since PHP 4.3.2.
error_prepend_stringNULLPHP_INI_ALL
error_append_stringNULLPHP_INI_ALL
error_logNULLPHP_INI_ALL
warn_plus_overloadingNULLThis option is no longer available as of PHP 4.0.0

List of Directory Functions

The following is the list of error handling functions supported in PHP. PHP - indicates the earliest versions of PHP that have support for the functions.

Sr.NoAdvanced & DescriptionPHP
1debug_backtrace()

Generates a backtrace

4
2debug_print_backtrace()

Prints a backtrace

5
3error_get_last()

Gets the last error occurred

5
4error_log()

Sends an error to the server error-log, to a file or to a remote destination

4
5error_reporting()

Specifies which errors are reported

4
6restore_error_handler()

Restores the previous error handler

4
7restore_exception_handler()

Restores the previous exception handler

5
8set_error_handler()

Sets a user-defined function to handle errors

4
9set_exception_handler()

Sets a user-defined function to handle exceptions

5
10trigger_error()

Creates a user-defined error message

4
11user_error()

Alias of trigger_error()

4

In our subsequent tutorials, we are going to be discussing about the above listed functions.

Directory Constants

The following is the list of error handling constants supported in PHP. PHP - indicates the earliest versions of PHP that have support for these constants.

You can make use of any of the constants while configuring your php.ini files.

ValueConstant & DescriptionPHP
1

E_ERROR

Fatal run-time errors. Errors that cannot be recovered from. Execution of the script is halted

2

E_WARNING

Non-fatal run-time errors. Execution of the script is not halted

4

E_PARSE

Compile-time parse errors. Parse errors should only be generated by the parser

5

E_NOTICE

Run-time notices. The script found something that might be an error, but could also happen when running a script normally

6

E_CORE_ERROR

Fatal errors at PHP startup. This is like an E_ERROR in the PHP core

4
7

E_CORE_WARNING

Non-fatal errors at PHP startup. This is like an E_WARNING in the PHP core

4
8

E_COMPILE_ERROR

Fatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine

4
9

E_COMPILE_WARNING

Non-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine

4
10

E_USER_ERROR

Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()

4
11

E_USER_WARNING

Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()

4
12

E_USER_NOTICE

User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()

4
13

E_STRICT

Run-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code

5
14

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

5
15

E_ALL

All errors and warnings, except of level E_STRICT

5


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about PHP debug_backtrace() Function.

Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.