The following code catches all files recursively in the php extension.
$paths = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($realPath), \RecursiveIteratorIterator::SELF_FIRST);
$files = new \RegexIterator($paths, '/\.(?:php)$/', \RegexIterator::MATCH);
foreach($files as $file){
...
I want to get files from any extension.
I want something to replace it: '/\.(?:php)$/'
Wouldn't you just change
/\.(?:php)$/
to
/.*/