What are the best practices for writing PHP code to avoid a white screen error?

When encountering a white screen error in PHP, it is often due to a fatal error in the code that stops the script from running. To avoid this issue, it is important to enable error reporting in PHP so that any errors are displayed on the screen. This can be achieved by setting the error_reporting level in the PHP configuration or by using the error_reporting function in the code.

// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);