What are some best practices for handling file paths in PHP scripts to avoid issues like empty string outputs?

When working with file paths in PHP scripts, it's important to handle them carefully to avoid issues like empty string outputs. One common practice is to use the `realpath()` function to normalize the file path and resolve any symbolic links or relative paths. Additionally, always check if the file path exists before performing any operations on it to prevent errors.

// Example of handling file paths in PHP to avoid empty string outputs
$file_path = '/path/to/file.txt';

// Normalize the file path
$real_path = realpath($file_path);

// Check if the file path exists
if ($real_path && file_exists($real_path)) {
    // Perform operations on the file
    echo "File path: " . $real_path;
} else {
    echo "Invalid file path";
}