这是我的功能:
protected function getContents($absoluteDirectoryPath = false, $recursive = false, $filter = "/.$/") {
if(!$absoluteDirectoryPath) return false;
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($absoluteDirectoryPath));
$files = new RegexIterator($iterator, $filter);
return $iterator;
}
我这样称呼它:
$pageFiles = $this->getContents($pagepath);
foreach($pageFiles as $file) {
echobr("PageFile: " . $file->fileName);
}
这是我得到的错误:
Notice: Undefined property: SplFileInfo::$fileName
如果我 var_dump$pageFiles
我得到这个:
object(DirectoryIterator)#5 (4) {
["pathName":"SplFileInfo":private]=>
string(68) "/home/domain/example/public/home/home.php"
["fileName":"SplFileInfo":private]=>
string(12) "home.php"
["glob":"DirectoryIterator":private]=>
bool(false)
["subPathName":"RecursiveDirectoryIterator":private]=>
string(0) ""
}
这是怎么回事?为什么我不能遍历结果?此目录中有 4 个文件,我应该能够输出文件名。