Error Handling in PHP Flashcards
Q: What is error handling in PHP?
A: The process of catching and managing errors to prevent application crashes.
Q: What are the types of errors in PHP?
A: Notices, Warnings, Fatal Errors, and Parse Errors.
Q: What function is used to trigger a user-defined error in PHP?
A: trigger_error().
Q: What is the default error reporting level in PHP?
A: E_ALL.
Q: How do you enable error reporting in PHP?
ini_set(‘display_errors’, 1);
error_reporting(E_ALL);
Q: What does E_NOTICE represent in PHP?
A: Non-critical runtime errors, like using undefined variables.
Q: What does E_WARNING represent in PHP?
A: Runtime errors that do not halt script execution.
Q: What does E_ERROR represent in PHP?
A: Critical runtime errors that halt script execution.
Q: What does E_PARSE represent in PHP?
A: Errors that occur during code parsing, such as syntax errors.
Q: What does E_ALL represent in PHP?
A: Reports all PHP errors except E_STRICT prior to PHP 5.4.
Q: What function retrieves the last error that occurred in PHP?
A: error_get_last().
Q: What function logs errors to a file in PHP?
A: error_log().
Q: How do you set a custom error handler in PHP?
A: Use the set_error_handler() function.
Q: How do you restore the previous error handler in PHP?
A: Use the restore_error_handler() function.
Q: How do you set a shutdown function to handle fatal errors?
A: Use the register_shutdown_function() function.
Q: What is the syntax for a custom error handler in PHP?
function customError($errno, $errstr, $errfile, $errline) {
// Handle the error
}
set_error_handler(‘customError’);