What potential pitfalls should be considered when using the is_dir function in PHP?

When using the is_dir function in PHP, it's important to remember that the function only checks if a given path is a directory and does not verify if the path actually exists. This can lead to potential pitfalls if the path provided is incorrect or does not exist, resulting in false positives or errors. To avoid this issue, it's recommended to first check if the path exists using the file_exists function before using is_dir.

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

if(file_exists($path) && is_dir($path)) {
    // Directory exists and is a valid directory
    // Your code here
} else {
    // Directory does not exist or is not a valid directory
    // Handle the error accordingly
}