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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pornel at despammed dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC