From: Operating system: CentOS 5.5 PHP version: 5.3.3 Package: Directory function related Bug Type: Bug Bug description:Folders being treated as files when scandir() is used
Description: ------------ Using scandir() to fetch a list of folders/files in a folder. When I use foreach() and is_dir() to filter out folders from files, folders and files are being grouped together, almost like PHP thinks the folders are files. However if we use "." as the argument in the scandir() method, we get the desired results. The below test script assumes you've created the following folders/files: folderName/ folderName/testFolder1/ folderName/testFolder2/ folderName/testFile1 folderName/testFile2 These results occur using both the CLI and via a PHP page in the browser. Test script: --------------- <?php // Example 1 $scan = scandir("folderName"); foreach ($scan as $file) { if (is_dir($file)) { echo "Folder: ".$file."\n"; } else { echo "File: ".$file."\n"; } } ?> <?php // Example 2 $scan = scandir("."); foreach ($scan as $file) { if (is_dir($file)) { echo "Folder: ".$file."\n"; } else { echo "File: ".$file."\n"; } } ?> Expected result: ---------------- Example 2 gives the expected result: Folder: . Folder: .. File: testFile1 File: testFile2 Folder: testFolder1 Folder: testFolder2 Actual result: -------------- Example 1 gives the actual result: Folder: . Folder: .. File: testFile1 File: testFile2 File: testFolder1 File: testFolder2 -- Edit bug report at http://bugs.php.net/bug.php?id=52471&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52471&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52471&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52471&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52471&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52471&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52471&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52471&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52471&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52471&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52471&r=support Expected behavior: http://bugs.php.net/fix.php?id=52471&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52471&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52471&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52471&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52471&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52471&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52471&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52471&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52471&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52471&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52471&r=mysqlcfg