|  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
 [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: Mon Oct 22 18:01:25 2018 UTC