How can error reporting in PHP be configured to better troubleshoot issues like data not being written to a file?

When troubleshooting issues like data not being written to a file in PHP, it is important to configure error reporting to display all errors, warnings, and notices. This can help identify any potential issues with file writing permissions, file paths, or syntax errors in the code.

// Set error reporting to display all errors, warnings, and notices
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Your file writing code here
$file = 'example.txt';
$data = 'Hello, world!';

if (file_put_contents($file, $data) === false) {
    echo "Error writing to file";
} else {
    echo "Data written to file successfully";
}