PHP5's DirectoryIterator

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

PHP5's DirectoryIterator

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I hadn't heard of SPL -- very extensive PHP 5 library. Does anybody use it? I'm assuming not for wide audiences?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

DirectoryIterator is okay, but nothing special. I find it easier to not use it, most often.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

What about SPL as a whole, feyd?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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."
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Imho the concept of an iterator was invented for languages that don't have a foreach operator...
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
sike
Forum Commoner
Posts: 84
Joined: Wed Aug 02, 2006 8:33 am

Post by sike »

i only use the "core" interfaces of spl (iterator, iteratoraggregate, countable, arrayaccess) on a regular basis.
Post Reply