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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC