How can error reporting be used effectively in PHP to debug code?
Error reporting can be used effectively in PHP to debug code by setting the error_reporting level to E_ALL, displaying errors on the screen, and logging errors to a file. This way, any errors or warnings in the code will be displayed in real-time, making it easier to identify and fix issues.
// Set error reporting level to display all errors
error_reporting(E_ALL);
// Display errors on the screen
ini_set('display_errors', 1);
// Log errors to a file
ini_set('log_errors', 1);
ini_set('error_log', '/path/to/error.log');