> Static typing. This is totally a question of taste but sometimes I would really love to have a bit more static typing in PHP. Guess what this following code does if you have a file named “1” in your directory
while ( ($filename = readdir($dh)) == true) $files[] = $filename;
Complete nitpick, but you don't even need static typing to fix that bug, just strong typing (like Python has it, for example).
If there's one breaking change that I believe a very large portion of the PHP community will appreciate, it is strong typing. In fact, it could easily be made an option, a mode in which == and === are the same and nothing automatically coerces. I bet that in many well-written projects, the amount of changes needed to be able to enable this option is pretty small.
I'm not sure if this could be easily built into PHP, but per-directory options are supported by PHP (when on apache, via a .htaccess file). If you could turn on or off strong typing per directory (or, alternatively, per file much like JS's "use strict"), there wouldn't be much of a practical problem.
It could even be a function modifier.
Unlike static typing or const correctness or immutability, strong typing is a very local feature that doesn't "bubble" across your codebase once you start using it.
Allowing .htaccess comes with a performance hit (Apache has to scan the directory and all of its parents for a .htaccess file on every pageview) and should generally not be used unless strictly necessary.
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.
That's just a bad argument. Simple code that suddenly breaks because of the contents of a directory shouldn't be possible, whether or not said simple code is unnecessary because of a standard library function. The example stands, weak typing is a horrible vector for difficult-to-catch bugs.
I whole-heartedly agree here. You really shouldn't have to implement workarounds to know you're comparing two integers, or two booleans. === feels like a workaround to me and the amount of times I've seen people forget the last = is high. That's probably my #1 gripe with PHP.
If there's one breaking change that I believe a very large portion of the PHP community will appreciate, it is strong typing. In fact, it could easily be made an option, a mode in which == and === are the same and nothing automatically coerces. I bet that in many well-written projects, the amount of changes needed to be able to enable this option is pretty small.