php.net |  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
Description:
------------
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:
---------------
<?php
function scan(RecursiveDirectoryIterator $dir)
{
	foreach($dir as $file)
	{
		var_dump($file->isDir());
		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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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: Fri Jul 20 21:01:24 2018 UTC