|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64533 recursive iterator makes dir become file
Submitted: 2013-03-27 13:37 UTC Modified: 2013-10-15 11:54 UTC
From: kasper at webmasteren dot eu Assigned:
Status: No Feedback Package: SPL related
PHP Version: Irrelevant OS: Windows 8 x64
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:
34 - 17 = ?
Subscribe to this entry?

 [2013-03-27 13:37 UTC] kasper at webmasteren dot eu
It is possible for the following code , to change a FOLDER to a "file", by SPL's 
functions, which only from what i have seen occures by the recursive itterator.

all there is needed is a folder structure like:

and those folders all have at least a file, in my particular case, "view.php".
The example, even prints what the old standard functions tell about the "path" 
from the element, and what the spl provides. 

Test script:
$recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator("pages\\a", \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($recursiveIterator as $element) { //the child first => top lvl first.
    var_dump("path:" . $element->getPath());

    if ($element->isFile()) {
        var_dump("Is file by new function(SPL)");
        var_dump("is dir by new function");

    if (\is_dir($element->getPath())) {
        var_dump("Is dir by old function");
        var_dump("is file by old function");
$f = new \SplFileInfo("pages\\a\\main");
var_dump($f->isDir()); //SHOULD BE TRUE!!

Expected result:
that SPL and the old functions would agree, and folders were reportet as folders.

Actual result:
That in SPL , inside of Recursive iterator and possibly recursiveDirectoryIterator 
folders becomes seen as files, causing it to report wrong type (only spl, not the 
old functions).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-27 14:26 UTC]
Is it only:

$f = new \SplFileInfo("pages\\a\\main");
var_dump($f->isDir()); //SHOULD BE TRUE!

that fails? Or previous calls fail too? Inside the foreach.

Also if you could provide a script that creates the structure and reproduce the 
bug, that would make the debugging session easier.
 [2013-03-27 14:26 UTC]
-Status: Open +Status: Feedback
 [2013-03-27 16:49 UTC] kasper at webmasteren dot eu
its is all inside of the loop that is wrong, it will print that by SPL the 
"folders" are files, (isFile() is true, and isDir() is false)
so heres a snippet to make the test files'n folders:
and then just use the orginal snippet.
what it will print is: 
string 'path:pages/a\main' (length=17)
string 'Is file by new function(SPL)' (length=28)
string 'Is dir by old function' (length=22)

which clealy shows that something must be wrong. 

the last line, the
var_dump($f->isDir()); //SHOULD BE TRUE!!
is to insure that the SplFileInfo is actually working, which means it must be in 
the iterator part ,somehow stuff gets wrong. (isDir()=true, so )
 [2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Sep 27 09:03:41 2022 UTC