PHP Error Functions

PHP Directory Functions
PHP Files Functions
  • On this page, you will find the functions to handle the errors that occur in the PHP script.
  • These functions allow us to specify our own method to handle the errors and log them.
  • Log functions allow us to redirect the logs/messages to other sources such as system logs or emails.
  • We can specify the kind of feedback or error whenever the error occurs.

No installation is required for these functions. They are included in the core language.

FunctionDescription
debug_backtrace()Generate a backtrace
debug_print_backtrace()Output a backtrace
error_clear_last()Clear the last error
error_get_last()Get the last error that occurred
error_log()Send error message to a log, to a file, or to a mail account
error_reporting()Specify which errors are reported
restore_error_handler()Restore the previous error handler
restore_exception_handler()Restore the previous exception handler
set_error_handler()Set user-defined error handler function
set_exception_handler()Set user-defined exception handler function
trigger_error()Create user-level error message
user_error()Alias of trigger_error()
Error functions in PHP

PHP Predefined Error and Logging Constants

ValueConstantDescription
1E_ERRORFatal run-time errors. Errors that cannot be recovered from. Execution of the script is halted
2E_WARNINGRun-time warnings (non-fatal errors). Execution of the script is not halted
4E_PARSECompile-time parse errors. Parse errors should only be generated by the parser
8E_NOTICERun-time notices. The script found something that might be an error, but could also happen when running a script normally
16E_CORE_ERRORFatal errors at PHP startup. This is like E_ERROR, except it is generated by the core of PHP
32E_CORE_WARNINGNon-fatal errors at PHP startup. This is like E_WARNING, except it is generated by the core of PHP
64E_COMPILE_ERRORFatal compile-time errors. This is like E_ERROR, except it is generated by the Zend Scripting Engine
128E_COMPILE_WARNINGNon-fatal compile-time errors. This is like E_WARNING, except it is generated by the Zend Scripting Engine
256E_USER_ERRORFatal user-generated error. This is like E_ERROR, except it is generated in PHP code by using the PHP function trigger_error()
512E_USER_WARNINGNon-fatal user-generated warning. This is like E_WARNING, except it is generated in PHP code by using the PHP function trigger_error()
1024E_USER_NOTICEUser-generated notice. This is like E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error()
2048E_STRICTEnable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code (Since PHP 5 but not included in E_ALL until PHP 5.4)
4096E_RECOVERABLE_ERRORCatchable fatal error. This indicates that a probably dangerous error occurred, but did not leave the Engine in an unstable state. If the error is not caught by a user-defined handle, the application aborts as it was an E_ERROR (Since PHP 5.2)
8192E_DEPRECATEDRun-time notices. Enable this to receive warnings about code that will not work in future versions (Since PHP 5.3)
16384E_USER_DEPRECATEDUser-generated warning message. This is like E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error() (Since PHP 5.3)
32767E_ALLEnable all PHP errors and warnings (except E_STRICT in versions < 5.4)
Error codes in PHP
PHP Directory Functions
PHP Files Functions
en English
X
Scroll to Top