What are common pitfalls when using PHP functions like is_dir() to check for directory existence?

One common pitfall when using PHP functions like is_dir() to check for directory existence is not handling edge cases properly, such as when the directory path is invalid or inaccessible. To solve this issue, it's important to validate the directory path before calling is_dir() to avoid potential errors.

$directory = '/path/to/directory';

if (is_dir($directory) && is_readable($directory)) {
    // Directory exists and is readable
    echo "Directory exists and is readable.";
} else {
    // Directory does not exist or is not readable
    echo "Directory does not exist or is not readable.";
}