What are best practices for error handling when using file_exists() in PHP to avoid unexpected T_IF errors?

When using file_exists() in PHP, it's important to handle errors properly to avoid unexpected T_IF errors. One best practice is to check if the file exists before attempting to access it, and handle any potential errors gracefully using conditional statements or try-catch blocks.

$filename = 'example.txt';

if (file_exists($filename)) {
    // File exists, proceed with accessing the file
    $file = fopen($filename, 'r');
    // Other file operations
} else {
    // File does not exist, handle the error accordingly
    echo 'File does not exist';
}