The following code returns different results in two environments (which however were supposed to be as close to one another as possible: the same PHP version, etc.)
The /var/www/html/project/vendor/package/path/to/some/folder
directory contains exactly the same set of files in both environments. The files themselves were put there by composer
.
use Symfony\Component\Finder\Finder;
// Don't mind this. The real app uses an autoloading mechanism.
require __DIR__ . '/../vendor/symfony/finder/Finder.php';
require __DIR__ . '/../vendor/symfony/finder/SplFileInfo.php';
require __DIR__ . '/../vendor/symfony/finder/Iterator/FilterIterator.php';
require __DIR__ . '/../vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php';
require __DIR__ . '/../vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php';
require __DIR__ . '/../vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php';
require __DIR__ . '/../vendor/symfony/finder/Iterator/PathFilterIterator.php';
require __DIR__ . '/../vendor/symfony/finder/Iterator/FilenameFilterIterator.php';
require __DIR__ . '/../vendor/symfony/finder/Iterator/FileTypeFilterIterator.php';
$path = '/var/www/html/project/vendor/package/path/to/some/folder';
$path = Finder::create()->files()->followLinks()->name('/\.(php|inc|hh)$/')->in($path);
$iterator = $path->getIterator();
$iterator->rewind();
$current = $iterator->current();
echo $current->getRelativePathname();
It isn't random. The results are consistent in a single environment. But a different path name is diplayed in either environment. I was able to trace it down to PHP's native: FilterIterator::rewind
, but I'm not sure if rewinding is the problem here.