Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Theres an OOP way to do this now with DirectoryIterator and RecursiveDirectoryIterator.

http://php.net/manual/en/class.directoryiterator.php

One of the big problems with PHP seems to be the amount of "hidden" features that you don't generally stumble upon unless you dive through the docs, or get the right google search.



> Theres an OOP way to do this now with DirectoryIterator and RecursiveDirectoryIterator.

OT: Iterators aren't OO.

First of all they don't work with objects/methods: we're forced to write a for/while loop, which is procedural programming. This also prevents abstraction and composition. Functions like "array_map" don't have these problems.

Second, they break encapsulation since they not only expose their elements, they also expose their internal mechanisms like "next", "rewind", etc. Again, array_map and friends win here.

Third, since they're a massive case of 'sequential coupling' ( http://en.wikipedia.org/wiki/Sequential_coupling ), and since objects are passed by reference, we must ensure that nothing we call in our loop body upsets the ordering (eg. by performing its own loop across the same iterator). This destroys encapsulation and modularity, and makes polymorphism and concurrency dangerous.

Just because something uses the "class" keyword doesn't mean it's OO.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: