|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-03-27 13:37 UTC] 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).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 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.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 )