[php-src] Issue #8167: PHP 8.1.3 *Iterator bug
| From: | Vermond125 | Date: | Thu, 03 Mar 2022 18:41:55 +0000 |
| Subject: | [php-src] Issue #8167: PHP 8.1.3 *Iterator bug | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240168@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8167
Comment Author: Vermond125
Thanx for fast reply, @iluuu1994!
My bad, I didn't provide full test, because it was coupled with framework and stuff, so here we
go:
The following code:
```php
<?php
$path = './Test';
$fileExtension = '.php';
$fileCount = 45;
// Prepare the sandbox
// Remove test sandbox
if (is_dir($path)) {
array_map('unlink', glob("$path/*.*"));
if (!rmdir($path)) {
throw new \RuntimeException(sprintf('Cannot recreate directory "%s"',
$path));
}
}
// Create test sandbox
if (!mkdir($path) && !is_dir($path)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created',
$path));
}
// Seed files inside test sandbox
for ($i = 0; $i < $fileCount; $i++) {
touch(sprintf('%s/%s%s',
$path,
sha1($i), // @note [!] I think it is hard for Iterator to swallow long names
$fileExtension)
);
}
// Main part
$iterator = new RegexIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY
),
'/^.+' . preg_quote($fileExtension) . '$/i',
RecursiveRegexIterator::GET_MATCH
);
// @note This line is an actual bugfix
// Add this line to get correct result
// foreach ($iterator as $file) {}
// Dummy loop to follow issue's case
$i = 0;
foreach ($iterator as $file) {
$i++;
}
echo "$i files found\n";
```
Resulted in this output:
```
14 files found
```
But I expected this output instead:
```
45 files found
```