php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37910 is_dir only returns TRUE on . and ..
Submitted: 2006-06-25 18:57 UTC Modified: 2006-06-26 08:52 UTC
From: andy dot shellam at mailnetwork dot co dot uk Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5.1.4 OS: Fedora Core 5
Private report: No CVE-ID: None
 [2006-06-25 18:57 UTC] andy dot shellam at mailnetwork dot co dot uk
Description:
------------
Running is_dir on an array of files returned from scandir, only returns TRUE on the "." and ".." directories.  Actually, is_dir returns nothing on anything except "." and "..".

I notice an extremely old bug #5693 had the same issue.

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

function SwitchRC($code)
{
        if ($code == 1)
        {
                return "TRUE";
        } else {
                return "FALSE";
        }
}

$Files = scandir("/");

for ($intC = 0; $intC < count($Files); $intC++)
{
        echo $Files[$intC] . " = " . SwitchRC(is_dir($Files[$intC])) . "\n";
}

?>


Expected result:
----------------
. = TRUE
.. = TRUE
.autofsck = TRUE
bin = TRUE
boot = TRUE
dev = TRUE
endeavour = TRUE
etc = TRUE
home = TRUE
lib = TRUE
lost+found = TRUE
media = TRUE
misc = TRUE
mnt = TRUE
net = TRUE
opt = TRUE
proc = TRUE
root = TRUE
sbin = TRUE
selinux = TRUE
srv = TRUE
sys = TRUE
test_text_file = FALSE
tmp = TRUE
usr = TRUE
var = TRUE

(test_text_file) is a file, everything else is a directory, as shown by the "ls -l /" output:

total 168
drwxr-xr-x  2 root root         4096 Jun 22 02:20 bin
drwxr-xr-x  3 root root         4096 Jun 19 19:19 boot
drwxr-xr-x  9 root root         3600 Jun 22 19:17 dev
drwxrwxr-x  9 root dataHandler  4096 Jun 25 01:29 endeavour
drwxr-xr-x 88 root root        12288 Jun 24 16:06 etc
drwxr-xr-x  7 root root         4096 Jun 21 22:39 home
drwxr-xr-x 11 root root         4096 Jun 21 19:14 lib
drwx------  2 root root        16384 Jun 19 20:02 lost+found
drwxr-xr-x  2 root root         4096 Feb 11 17:16 media
drwxr-xr-x  2 root root         4096 Feb 11 03:06 misc
drwxr-xr-x  2 root root         4096 Feb 11 17:16 mnt
drwxr-xr-x  2 root root            0 Jun 22 19:17 net
drwxr-xr-x  2 root root         4096 Feb 11 17:16 opt
dr-xr-xr-x 91 root root            0 Jun 22 20:15 proc
drwxr-x--- 13 root root         4096 Jun 20 01:43 root
drwxr-xr-x  2 root root        12288 Jun 20 22:37 sbin
drwxr-xr-x  3 root root            0 Jun 22 20:15 selinux
drwxr-xr-x  2 root root         4096 Feb 11 17:16 srv
drwxr-xr-x 11 root root            0 Jun 22 20:15 sys
-rw-r--r--  1 root root           25 Jun 25 02:47 test_text_file
drwxrwxrwt 10 root root         4096 Jun 25 02:48 tmp
drwxr-xr-x 14 root root         4096 Jun 19 19:14 usr
drwxr-xr-x 22 root root         4096 Jun 19 19:36 var

Actual result:
--------------
. = TRUE
.. = TRUE
.autofsck = FALSE
bin = FALSE
boot = FALSE
dev = FALSE
endeavour = FALSE
etc = FALSE
home = FALSE
lib = FALSE
lost+found = FALSE
media = FALSE
misc = FALSE
mnt = FALSE
net = FALSE
opt = FALSE
proc = FALSE
root = FALSE
sbin = FALSE
selinux = FALSE
srv = FALSE
sys = FALSE
test_text_file = FALSE
tmp = FALSE
usr = FALSE
var = FALSE


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-25 19:09 UTC] tony2001@php.net
You forgot to add "/" to the directory name.
 [2006-06-26 08:41 UTC] andy dot shellam at mailnetwork dot co dot uk
The output is coming directly from scandir, so if a / was needed, surely scandir should add it in for directories?

Also is_dir doesn't actually return false, it just returns Null.
 [2006-06-26 08:52 UTC] tony2001@php.net
http://php.net/scandir - it doesn't add directory to the result filenames, you have to add it yourself.
No bug here.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC