RecursiveDirectoryIterator and foreach
| From: | Ryan Panning | Date: | Mon, 23 Feb 2009 16:31:04 +0000 |
| Subject: | RecursiveDirectoryIterator and foreach | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-288681@lists.php.net to get a copy of this message | ||
I have discovered that when I foreach over a RecursiveDirectoryIterator (see example below) the $item actually turns into a SplFileInfo object. I would expect it to be a RecursiveDirectoryIterator. How do I do a hasChildren() on SplFileInfo?
However, if I change it to a non-recursive, DirectoryIterator, $item is what I would expect, DirectoryIterator. I've tested this with 5.2.8 and 5.3b1. I'm guessing this is an issue with my setup as I'm sure I've gotten this to work before...
$dir = new RecursiveDirectoryIterator('/path/to/dir');
foreach ($dir as $item) {
print get_class($item) . "\r\n";}