PHP Error Handling and Debugging Flashcards
(25 cards)
What is error handling in PHP?
Error handling manages errors during script execution to prevent crashes and provide meaningful feedback.
In WordPress, error handling ensures plugins don’t break sites. Freelancers use it to deliver reliable code, while enterprise architects implement robust error handling for stable, high-traffic systems, aligning with your security focus.
What is a PHP error?
A PHP error is an issue in code execution, like syntax errors or undefined variables.
Errors disrupt scripts, e.g., a missing semicolon in a WordPress plugin. Freelancers fix errors for clients, while enterprise architects log and monitor errors to maintain system reliability.
What is a syntax error in PHP?
A syntax error occurs due to incorrect code structure, like echo “Hello (missing quote).
In WordPress, syntax errors break templates. Freelancers debug them using editors, while enterprise architects use linters to catch syntax issues early in large codebases.
What is a runtime error in PHP?
A runtime error occurs during execution, like dividing by zero ($x = 5 / 0;).
In WordPress, accessing undefined post meta causes runtime errors. Freelancers handle them with checks, while enterprise architects use defensive programming to prevent runtime issues.
What is a fatal error in PHP?
A fatal error stops script execution, like calling an undefined function.
In WordPress, a missing plugin function triggers fatal errors. Freelancers debug fatal errors for clients, while enterprise architects ensure critical functions are defined in enterprise systems.
What is a warning in PHP?
A warning is a non-fatal error that allows execution, like accessing an undefined array key.
In WordPress, warnings occur with unset variables (e.g., $post->meta). Freelancers suppress or fix warnings, while enterprise architects log them for proactive resolution.
What is a notice in PHP?
A notice is a minor issue, like using an undefined variable.
In WordPress, notices appear in debug mode (e.g., $x before assignment). Freelancers resolve notices for clean code, while enterprise architects eliminate them to ensure robust systems.
What is the error_reporting() function in PHP?
error_reporting() sets which errors are reported, like error_reporting(E_ALL);.
In WordPress, it’s used with WP_DEBUG. Freelancers configure it for debugging, while enterprise architects disable reporting in production to hide sensitive data, per your security deck.
What is ini_set(‘display_errors’, 0) in PHP?
It disables error display in production, like ini_set(‘display_errors’, 0);.
In WordPress, it prevents error exposure. Freelancers secure client sites, while enterprise architects combine it with logging for secure error management.
What is the error_log() function in PHP?
error_log() writes errors to a log file, like error_log(“Error occurred”);.
In WordPress, it logs issues for debugging. Freelancers use it for client sites, while enterprise architects integrate it with monitoring tools for enterprise systems.
What is a try-catch block in PHP?
A try-catch block handles exceptions, like try { /* code */ } catch (Exception $e) { echo $e->getMessage(); }.
In WordPress, it’s used for database queries. Freelancers catch errors in plugins, while enterprise architects use try-catch for robust exception handling, as in your database deck.
What is an exception in PHP?
An exception is an object thrown to signal an error, like throw new Exception(“Error”);.
In WordPress, exceptions handle failed API calls. Freelancers manage exceptions for reliability, while enterprise architects design custom exceptions for system-specific errors.
How do you throw an exception in PHP?
Use throw, like throw new Exception(“Invalid input”);.
In WordPress, plugins throw exceptions for invalid data. Freelancers use it for error signaling, while enterprise architects ensure meaningful exception messages.
What is the Exception class in PHP?
The Exception class is the base class for exceptions, providing methods like getMessage().
In WordPress, it’s extended for custom exceptions. Freelancers use it in plugins, while enterprise architects create hierarchies for structured error handling.
What is set_exception_handler() in PHP?
set_exception_handler() defines a function to handle uncaught exceptions, like set_exception_handler(‘myHandler’);.
In WordPress, it centralizes error handling. Freelancers use it for custom logging, while enterprise architects integrate it with monitoring systems.
What is set_error_handler() in PHP?
set_error_handler() defines a function to handle errors, like set_error_handler(‘myErrorHandler’);.
In WordPress, it captures warnings/notices. Freelancers log errors for clients, while enterprise architects use it for comprehensive error tracking.
What is the var_dump() function in PHP?
var_dump() displays detailed variable information, like var_dump($array);.
In WordPress, it debugs post data. Given your array experience, freelancers use it for troubleshooting, while enterprise architects prefer structured debugging tools.
What is the print_r() function in PHP?
print_r() displays readable variable information, like print_r($array, true);.
In WordPress, it inspects arrays (e.g., $post). Freelancers use it for quick debugging, while enterprise architects limit its use in production for security.
What is Xdebug in PHP?
Xdebug is a PHP extension for advanced debugging and profiling.
It provides stack traces and breakpoints. Freelancers use Xdebug in XAMPP for WordPress, while enterprise architects leverage it for performance analysis in large systems.
What is WP_DEBUG in WordPress?
WP_DEBUG is a constant that enables debugging mode, defined as define(‘WP_DEBUG’, true);.
It displays errors and notices. Freelancers enable it for development, while enterprise architects disable it in production, aligning with your security deck.
What is WP_DEBUG_LOG in WordPress?
WP_DEBUG_LOG logs errors to a file, defined as define(‘WP_DEBUG_LOG’, true);.
Logs are saved in wp-content/debug.log. Freelancers use it for client debugging, while enterprise architects integrate logs with monitoring tools.
What is WP_DEBUG_DISPLAY in WordPress?
WP_DEBUG_DISPLAY controls error display, defined as define(‘WP_DEBUG_DISPLAY’, false);.
Disables on-screen errors. Freelancers secure client sites, while enterprise architects ensure errors are logged, not displayed, for security.
What is a stack trace in PHP?
A stack trace shows the call sequence leading to an error, accessed via debug_print_backtrace().
In WordPress, it traces plugin errors. Freelancers analyze traces, while enterprise architects use them to pinpoint issues in complex systems.
What is the trigger_error() function in PHP?
trigger_error() generates a user-defined error, like trigger_error(“Custom error”, E_USER_WARNING);.
In WordPress, it logs custom issues. Freelancers use it for debugging, while enterprise architects integrate it with error reporting systems.