What are common pitfalls when checking if a directory is empty in PHP?
A common pitfall when checking if a directory is empty in PHP is using the `scandir()` function and checking if the count of the returned array is 2 (for `.` and `..`). This method can lead to incorrect results if hidden files are present in the directory. To accurately check if a directory is empty, it's better to use `glob()` with a wildcard pattern and check if it returns an empty array.
$files = glob('/path/to/directory/*');
if (count($files) === 0) {
echo "Directory is empty";
} else {
echo "Directory is not empty";
}