|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75135 Elements of DirectoryIterator is the iterator itself
Submitted: 2017-08-29 17:38 UTC Modified: -
From: morozov at tut dot by Assigned:
Status: Open Package: SPL related
PHP Version: 7.1.8 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: morozov at tut dot by
New email:
PHP Version: OS:


 [2017-08-29 17:38 UTC] morozov at tut dot by
When iterating over a DirectoryIterator, each element is the iterator itself representing the current file. It makes it impossible to convert the iterator to array, as all its elements will be references to the same object (the iterator).


Test script:
$it = new DirectoryIterator('/tmp');
$array = iterator_to_array($it);

foreach ($array as $fileInfo) {





Expected result:
The expected result is to see real paths of the files under the /tmp directory. It works if the iterator is iterated directly, without being converted to an array first.

Actual result:
The actual result is all real paths are FALSE since after having been converted to an array, the directory iterator is in an invalid state.


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Apr 12 17:01:24 2021 UTC