|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
28 + 50 = ?
Subscribe to this entry?

 [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-2020 The PHP Group
All rights reserved.
Last updated: Mon Sep 21 16:01:24 2020 UTC