RecursiveFilterIterator::accept 过滤名为“0”的目录

RecursiveFilterIterator::accept filters ous directories called "0"

我有这个简单的 class:

class MyRecursiveFilterIterator extends RecursiveFilterIterator {

    public function accept() {
        $filename = $this->current()->getFilename();

        // Skip hidden files and directories.
        if ($filename[0] === '.') {
            return false;
        }

        return (string)$filename;
    }

}

然后我简单地使用它:

$directory = new RecursiveDirectoryIterator($path, FilesystemIterator::FOLLOW_SYMLINKS);
$filter = new MyRecursiveFilterIterator($directory);
$iterator = new RecursiveIteratorIterator($filter);
$files = array();
foreach ($iterator as $info) {
    $files[] = $info->getPathname();
}
var_dump($files);

问题是即使 RecursiveFilterIterator::accept 有时 returns string(1) "0" 它被解释为 false 并且目录被跳过。

我怎样才能让它与名为“0”的目录一起工作?

Return true 而不是文件名。