php.net |  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:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-08-29 17:38 UTC] morozov at tut dot by
Description:
------------
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).

See https://3v4l.org/P0H06.

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

foreach ($array as $fileInfo) {
    var_dump($fileInfo->getRealPath());
}

/*

Outputs:

bool(false)
bool(false)

*/

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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC