以下代码在两种环境中返回不同的结果(但是应该尽可能地相互接近:相同的 PHP 版本等)
该/var/www/html/project/vendor/package/path/to/some/folder
目录在两种环境中都包含完全相同的文件集。文件本身是由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();
这不是随机的。结果在单一环境中是一致的。但是在任一环境中都会显示不同的路径名。我能够将其追溯到 PHP 的本机: FilterIterator::rewind
,但我不确定倒带是否是这里的问题。