How can error reporting be optimized for PHP scripts to catch potential issues early on?

To optimize error reporting for PHP scripts and catch potential issues early on, you can enable error reporting, set error reporting level to include all types of errors, and log errors to a file for easy troubleshooting.

// Enable error reporting
error_reporting(E_ALL);

// Set error reporting level to include all types of errors
ini_set('display_errors', 1);

// Log errors to a file for easy troubleshooting
ini_set('error_log', '/path/to/error.log');