What potential issue arises in the provided PHP code when trying to create a file list recursively?

The potential issue in the provided PHP code when trying to create a file list recursively is that the `readdir()` function is not being used correctly to read directories. To solve this issue, we need to modify the code to check if the current item is a directory before recursively calling the function to list its contents.

function listFiles($dir){
    $files = [];
    
    if(is_dir($dir)){
        $handle = opendir($dir);
        
        while(false !== ($file = readdir($handle))){
            if($file != '.' && $file != '..'){
                $fullPath = $dir . '/' . $file;
                
                if(is_dir($fullPath)){
                    $files = array_merge($files, listFiles($fullPath));
                } else {
                    $files[] = $fullPath;
                }
            }
        }
        
        closedir($handle);
    }
    
    return $files;
}

// Usage
$directory = '/path/to/directory';
$fileList = listFiles($directory);

print_r($fileList);