Bug #75135 [NEW]: Elements of DirectoryIterator is the iterator itself
From: morozov at tut dot by
Operating system: Linux
PHP version: 7.1.8
Package: SPL related
Bug Type: Bug
Bug description:Elements of DirectoryIterator is the iterator itself
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.
--
Edit bug report at https://bugs.php.net/bug.php?id=75135&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75135&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75135&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75135&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75135&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75135&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75135&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75135&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75135&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75135&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75135&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75135&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75135&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75135&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75135&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75135&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75135&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75135&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75135&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75135&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75135&r=mysqlcfg
Thread (1 message)
- morozov at tut dot by