Junior
What error levels exist in PHP?
sobes.tech AI
Answer from AI
In PHP, there is a hierarchical system of error levels:
- E_ERROR: Fatal runtime errors that cannot be handled by the script. They cause immediate termination.
- E_WARNING: Non-fatal runtime errors. The script continues to run.
- E_PARSE: Syntax errors detected by the parser.
- E_NOTICE: Notices about things that may indicate an error but can also be planned (e.g., accessing an undefined variable). The script continues to run.
- E_CORE_ERROR: Fatal errors that occur during PHP's initial startup.
- E_CORE_WARNING: Non-fatal errors during PHP's startup.
- E_COMPILE_ERROR: Fatal errors detected during compilation.
- E_COMPILE_WARNING: Non-fatal errors detected during compilation.
- E_USER_ERROR: Fatal error generated by the user using the
trigger_error()function. - E_USER_WARNING: Non-fatal error generated by the user.
- E_USER_NOTICE: Notice generated by the user.
- E_STRICT: Runtime notices that suggest changes to the code for better compatibility or performance.
- E_RECOVERABLE_ERROR: Almost fatal error. The script will not terminate if the handler is called, but if this handler does not call
die(), the script will terminate. - E_DEPRECATED: Notices about code that will be deprecated and/or removed in future PHP versions.
- E_USER_DEPRECATED: Notices generated by the user about deprecated code.
- E_ALL: All errors and warnings except E_STRICT. (In PHP 6, its value became E_ALL | E_STRICT).
Error levels can be configured in the php.ini file using the error_reporting directive or dynamically in the script using the error_reporting() function.
For example:
<?php
error_reporting(E_ALL & ~E_NOTICE); // Enable all errors except notices
?>