#49755 [Opn]: iterator_to_array nukes DirectoryIterator

From: Date: Fri, 02 Oct 2009 21:09:31 +0000
Subject: #49755 [Opn]: iterator_to_array nukes DirectoryIterator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-143201@lists.php.net to get a copy of this message
 ID:               49755
 Updated by:       fa@php.net
 Reported By:      salathe@php.net
 Status:           Open
 Bug Type:         SPL related
 Operating System: OS X
 PHP Version:      5.3.0
 New Comment:

Not 5.3.0 only, also reproducable on a
"PHP 5.2.6-1+lenny3 with Suhosin-Patch 0.9.6.2"


Previous Comments:
------------------------------------------------------------------------

[2009-10-02 19:02:20] salathe@php.net

Description:
------------
When converting a DirectoryIterator instance into an array using
iterator_to_array, the array items appear to be converted to basic
DirectoryIterator instances with none of the file information intact.
The same does not appear to occur for other related classes
(FilesystemIterator, RecursiveDirectoryIterator).

Reproduce code:
---------------
<?php

echo "DirectoryIterator:\n";
$dit = new DirectoryIterator(dirname(__FILE__));
$ait = iterator_to_array($dit);
foreach ($ait as $file) {
	var_dump($file->getFilename());
}

echo "RecursiveDirectoryIterator:\n";
$rdit = new RecursiveDirectoryIterator(dirname(__FILE__));
$ait = iterator_to_array($rdit);
foreach ($ait as $file) {
	var_dump($file->getFilename());
}

?>

Expected result:
----------------
DirectoryIterator:
string(1) "."
string(2) ".."
string(7) "bug.php"
RecursiveDirectoryIterator:
string(7) "bug.php"


Actual result:
--------------
DirectoryIterator:
string(0) ""
string(0) ""
string(0) ""
RecursiveDirectoryIterator:
string(7) "bug.php"



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49755&edit=1



Thread (6 messages)

« previous php.bugs (#143201) next »