FilessytemIterator Skips Dot Files¶
FilessytemIterator class used to list the current directory .
and the parent directory ..
. Files starting with a dot were and are still listed.
In PHP 8.2, the dot files are not listed by default. At instantiation time, it is possible to have those file listed by using the FilesystemIterator::SKIP_DOTS option.
PHP code¶
<?php
// $dir is a path to a folder that contains 2 files: a.txt and .b
$it = new FilesystemIterator(dirname($dir), FilesystemIterator::CURRENT_AS_FILEINFO);
foreach ($it as $fileinfo) {
echo $fileinfo->getFilename() . "\n";
}
?>
Before¶
.
..
a.txt
.b
After¶
.
..
a.txt
.b
PHP version change¶
This behavior changed in 8.1