[php-src] Issue #8167: PHP 8.1.3 *Iterator bug
| From: | Vermond125 | Date: | Thu, 03 Mar 2022 16:31:03 +0000 |
| Subject: | [php-src] Issue #8167: PHP 8.1.3 *Iterator bug | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240165@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8167
Author: Vermond125
### Description
An original weird behavior was found in
doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/AnnotationDriver.php, but is related to
php base classes.
I have 47 files, but this code finds only one of them.
To fix this, I can simply put an additional line after the
$iterator is defined:
```php
foreach ($iterator as $file) {}
```
It makes no sence other than internal warmup of some sort, but after it in the next loop I can
actually see all 47 files.
The following code:
```php
<?php
// ...
$iterator = new RegexIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY
),
'/^.+' . preg_quote($this->fileExtension) . '$/i',
RecursiveRegexIterator::GET_MATCH
);
foreach ($iterator as $file) {
```
Resulted in this output:
```
1 file found
```
But I expected this output instead:
```
47 files found
```
### PHP Version
PHP 8.1.3
### Operating System
Ubuntu 20.04.1