Issue: https://github.com/php/php-src/issues/11573
Author: mvorisek
### Description

I belive the currently php-src impl. checks if any iterated item has children on each
RecursiveDirectoryIterator::hasChildren call. This is slow.
I propose to cache the scanned files list with a file flag. If a current item is a file, it cannot
have children and it will optimize typical usecase - directory with many regular files.