Different Methods to Show Error Messages In PHP
PHP Errors
We use error functions to deal with error logging and error handling.
Types of Errors:
There are two types of errors:
- Internal Error
These are logical errors in code.
- External Error
These are errors related to the interactions of your code with the outside world.
Dealing with Error:
When we have figured out the error we can use the following ways to deal with them:
- Display the Error: This shows the error to the developer and/or user when the program is executed.
- Log the Error: Store the errors and review them from a textual log file
- Act on the Error: Each program will need a different type of action.
- Ignore the Error: This should continually be avoided.
Showing Errors:
There are Four possible ways:
- error_reporting()
- display_errors()
- log_errors()
- error_log string()
Turn off error reporting:
1 2 3 |
<?php error_reporting(0)
; ?> |
Report all errors:
1 2 3 |
<?php error_reporting(E_ALL); ?> |
1 2 3 |
<?php ini_set("error_reporting", E_ALL); ?> |
Report runtime errors:
1 2 3 |
<?php error_reporting(E_ERROR | E_WARNING | E_PARSE); ?> |
Report all Except E_Notice:
1 2 3 |
<?php error_reporting(E_ALL & ~E_NOTICE); ?> |