{"record":{"id":"86c97b07cd7663d9","repo":"symfony/finder","slug":"this-iterator-only-support-returning-current-as-fileinfo","errorCode":null,"errorMessage":"This iterator only support returning current as fileinfo.","messagePattern":"This iterator only support returning current as fileinfo\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Iterator/RecursiveDirectoryIterator.php","lineNumber":40,"sourceCode":" * @extends \\RecursiveDirectoryIterator<string, SplFileInfo>\n */\nclass RecursiveDirectoryIterator extends \\RecursiveDirectoryIterator\n{\n    private bool $ignoreUnreadableDirs;\n    private bool $ignoreFirstRewind = true;\n\n    // these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations\n    private string $rootPath;\n    private string $subPath;\n    private string $directorySeparator = '/';\n\n    /**\n     * @throws \\RuntimeException\n     */\n    public function __construct(string $path, int $flags, bool $ignoreUnreadableDirs = false)\n    {\n        if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {\n            throw new \\RuntimeException('This iterator only support returning current as fileinfo.');\n        }\n\n        parent::__construct($path, $flags);\n        $this->ignoreUnreadableDirs = $ignoreUnreadableDirs;\n        $this->rootPath = $path;\n        if ('/' !== \\DIRECTORY_SEPARATOR && !($flags & self::UNIX_PATHS)) {\n            $this->directorySeparator = \\DIRECTORY_SEPARATOR;\n        }\n    }\n\n    /**\n     * Return an instance of SplFileInfo with support for relative paths.\n     */\n    public function current(): SplFileInfo\n    {\n        // the logic here avoids redoing the same work in all iterations\n\n        if (!isset($this->subPath)) {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/symfony/finder/blob/4d6c057bfd67c5a93e8025c85ca9364cba7e260a/Iterator/RecursiveDirectoryIterator.php#L22-L58","documentation":"RecursiveDirectoryIterator (the Finder one) only supports CURRENT_AS_FILEINFO mode; if the $flags bitmask includes SplFilesystemIterator::CURRENT_AS_PATHNAME or CURRENT_AS_SELF it throws RuntimeException because current() would not return the SplFileInfo the Finder ecosystem depends on.","triggerScenarios":"new RecursiveDirectoryIterator($path, \\FilesystemIterator::CURRENT_AS_PATHNAME) or CURRENT_AS_SELF, or building flags with SKIP_DOTS/CURRENT_AS_PATHNAME combos passed into the constructor or Finder internals.","commonSituations":"Copy-pasting flags from native SplDirectoryIterator usage, trying to iterate pathnames directly instead of via getPathname(), refactoring code that used the SPL iterator's flag semantics.","solutions":["Use flags without CURRENT_AS_* overrides, e.g. \\FilesystemIterator::SKIP_DOTS | \\FilesystemIterator::UNIX_PATHS","If you need pathnames, keep the default (SplFileInfo) and call (string)$file or $file->getPathname()","If you need CURRENT_AS_PATHNAME semantics, use native \\RecursiveDirectoryIterator/\\RecursiveIteratorIterator instead of this class"],"exampleFix":"// before\n$it = new RecursiveDirectoryIterator($path, \\FilesystemIterator::CURRENT_AS_PATHNAME | \\FilesystemIterator::SKIP_DOTS);\n// after\n$it = new RecursiveDirectoryIterator($path, \\FilesystemIterator::SKIP_DOTS);\nforeach ($it as $fileInfo) { $path = $fileInfo->getPathname(); }","handlingStrategy":"validation","validationCode":"if ($flags & (\\FilesystemIterator::CURRENT_AS_PATHNAME | \\FilesystemIterator::CURRENT_AS_SELF)) { throw new \\RuntimeException('Unsupported CURRENT_AS_* flag'); }","typeGuard":"function hasSupportedCurrentFlags(int $flags): bool { return ($flags & (\\FilesystemIterator::CURRENT_AS_PATHNAME | \\FilesystemIterator::CURRENT_AS_SELF)) === 0; }","tryCatchPattern":"try { $it = new RecursiveDirectoryIterator($path, $flags); } catch (\\RuntimeException $e) { /* fix flags */ }","preventionTips":["Only combine SKIP_DOTS, UNIX_PATHS, FOLLOW_SYMLINKS with this iterator — no CURRENT_AS_* flags","Get pathnames via $fileInfo->getPathname() instead of flags","Use native SPL iterators if you need CURRENT_AS_PATHNAME semantics"],"tags":["iteration","flags","filesystem"],"backgroundTag":"unsupported-operation","analyzedSha":"4d6c057bfd67c5a93e8025c85ca9364cba7e260a","analyzedAt":"2026-09-13T07:49:33.433Z","contentChangedAt":"2026-09-13T07:49:33.433Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}