What are the best practices for working with file paths in PHP when using functions like is_dir?

When working with file paths in PHP, it is important to ensure that the paths are properly formatted to avoid errors when using functions like `is_dir`. To do this, you can use the `realpath` function to normalize the path and ensure it is in the correct format before passing it to functions like `is_dir`.

$path = '/path/to/directory';
$normalized_path = realpath($path);

if ($normalized_path && is_dir($normalized_path)) {
    echo "The directory exists.";
} else {
    echo "The directory does not exist.";
}