|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37070 SplFileObject::isDir() returns false for empty dirs
Submitted: 2006-04-13 12:19 UTC Modified: 2006-04-13 12:29 UTC
From: pornel at despammed dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 6CVS-2006-04-13 (snap) OS: OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: pornel at despammed dot com
New email:
PHP Version: OS:


 [2006-04-13 12:19 UTC] pornel at despammed dot com
I'm using RecursiveDirectoryIterator to scan directories.

File objects returned by this iterator seem to threat isDir and hasChildren as the same thing. That is isDir returns true only when item has children. 

This assumption is invalid and causes empty directories to be reported as files.

Reproduce code:
function scan(RecursiveDirectoryIterator $dir)
	foreach($dir as $file)
		if ($dir->hasChildren()) scan($dir->getChildren());
scan(new RecursiveDirectoryIterator('/some/path/that/has/empty/dirs'));

Expected result:
isDir should not act as alias of hasChildren

Actual result:
empty directories have isFile()==true and isDir()==false


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-13 12:29 UTC] pornel at despammed dot com
My bad. Confused getPath with getPathname.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sat Dec 15 22:01:26 2018 UTC