Bug #64533 [Fbk->NoF]: recursive iterator makes dir become file
| From: | php-bugs at lists dot php dot net | Date: | Tue, 15 Oct 2013 11:54:41 +0000 |
| Subject: | Bug #64533 [Fbk->NoF]: recursive iterator makes dir become file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182235@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64533&edit=1
ID: 64533
Updated by: php-bugs@lists.php.net
Reported by: kasper at webmasteren dot eu
Summary: recursive iterator makes dir become file
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: SPL related
Operating System: Windows 8 x64
PHP Version: Irrelevant
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-03-27 16:49:58] 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:
-----------------------------------
mkdir("pages");
mkdir("pages/a");
mkdir("pages/a/main");
mkdir("pages/a/main.menu");
mkdir("pages/a/main.bottom");
mkdir("pages/a/main.top");
fopen("pages/a/main/view.php","w+");
fopen("pages/a/main.menu/view.php","w+");
fopen("pages/a/main.bottom/view.php","w+");
fopen("pages/a/main.top/view.php","w+");
-----------------------------------
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-03-27 14:26:17] pajoye@php.net
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 13:37:06] kasper at webmasteren dot eu
Description:
------------
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:
pages/a
/main
/main.top
/main.content
/main.menu
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)");
}
if($element->isDir()){
var_dump("is dir by new function");
}
if (\is_dir($element->getPath())) {
var_dump("Is dir by old function");
}
if(\is_file($element->getPath())){
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).
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64533&edit=1