Page 1 of 1

PHP5's DirectoryIterator

Posted: Tue Oct 10, 2006 12:34 pm
by Luke
Does anybody use this? Is it useful? Anybody know of any good resources on it? It seems pretty straight-forward, but I was just wondering what kinds of things (if any) people are doing with it. I am building version three of our File Manager application and I would like for it to be my most geniusly well-written, well-thought out, and well-researched application so far. I want to make sure if I use this, it's recommended by my peers.

Posted: Tue Oct 10, 2006 12:35 pm
by Chris Corbyn
I guess this is a SPL thing. I haven't delved into any of the SPL stuff yet. Heck, gentoo has it turned off in its USE flags by default.

Posted: Tue Oct 10, 2006 12:44 pm
by Luke
I found this resource on it...
http://www.sitepoint.com/article/php5-standard-library
d11wqt wrote:I haven't delved into any of the SPL stuff yet.
Any specific reason why not? Is it because of the gentoo thing?

Posted: Tue Oct 10, 2006 12:44 pm
by neophyte
I hadn't heard of SPL -- very extensive PHP 5 library. Does anybody use it? I'm assuming not for wide audiences?

Posted: Tue Oct 10, 2006 12:54 pm
by feyd
DirectoryIterator is okay, but nothing special. I find it easier to not use it, most often.

Posted: Tue Oct 10, 2006 12:55 pm
by Luke
What about SPL as a whole, feyd?

Posted: Tue Oct 10, 2006 1:14 pm
by feyd
For the most part, I avoid the SPL as it's fairly slow. While it's pretty good OOP, it could potentially be written "better."

Posted: Tue Oct 10, 2006 3:10 pm
by timvw
Imho the concept of an iterator was invented for languages that don't have a foreach operator...

Posted: Tue Oct 10, 2006 3:28 pm
by dbevfat
I've used DirectoryIterator several times and it's definitely a nice way to iterate through files.

Code: Select all

$di = new DirectoryIterator('path');
foreach ($di as $file)
  echo $file->getFilename(); // or just echo $file;
The $file holds an object that implements various methods to ease development, such is isDot(), isFile(), isDir(), isReadable() ... So neat and simple I haven't looked back. Compare this to the opendir()-style and you'll see why.

Another resource for DirectoryIterator: http://wiki.cc/php/Iterator_Directory.

Posted: Tue Oct 10, 2006 3:30 pm
by RobertGonzalez
I actually ran across this for the first time this morning. Didn't really look into it enough to even know what it was. But I might look a little closer.

Posted: Tue Oct 10, 2006 4:18 pm
by Jenk
Gentoo has a lot of stuff off by default. bcmath, curl and so on that would normally be 'on' with a manual install. Dunno why.. guess who ever made the package decided for bare minimum, which makes sense I guess.

The only part of the SPL I have found myself using a fair amount is Reflection.

Posted: Tue Oct 10, 2006 4:22 pm
by Christopher
timvw wrote:Imho the concept of an iterator was invented for languages that don't have a foreach operator...
Java has one now because being forced to use Iterators for everything gets very old.

Posted: Wed Oct 11, 2006 2:31 am
by sike
i only use the "core" interfaces of spl (iterator, iteratoraggregate, countable, arrayaccess) on a regular basis.