3 ms·
There are some good reasons to like PHP but the array functions in the standard library are not one of them. * Arrays are created with array() as opposed to a
by generalk 15y ago
There are some good reasons to like PHP but the array functions in the standard library are not one of them.
* Arrays are created with array() as opposed to a more modern [].
* Arrays are not objects, so you have a ton of functions in the global namespace starting with array -- array_join() as opposed to $array->join().
* The functions are not consistent. Half of them don't have "array_" as a prefix. The order of arguments isn't consistent with other parts of the standard library.
I'm really curious about why you consider this a strong point of PHP.
- sequoia 15y agoI hear what you're saying about arrays not being objects and there's really no excuse for the conflicting ($array, $argument) & ($argument, $array) signatures of many functions, but regarding "array() as opposed to a more modern []:" whenever I read this I can't help but think "Who fucking cares??" When people want to pick nits about this or significant whitespace it makes me think that there must very little variance between the languages if THIS is the issue that deserves scrutiny. Am I missing something about array() vs [] ? if you really hate typing array(), http://codepad.org/ASREdjTK http://codepad.org/ASREdjTK
- ianterrell 15y agoIt's not nitpicking to want consistency of convention. When I work with an unfamiliar class in Ruby, or come back to something familiar (say, Array) after a long time away, I'll often not "know" the exact method signatures for what I want, but I'll just guess something reasonable based on my knowledge of the language and idioms. And, lo and behold, most often it works! Having to "remember" (does this method use array_?) or "translate" is a mental tax; there's cycles wasted that could keep your mind in the business logic.
- generalk 15y ago> When people want to pick nits about this or significant whitespace > it makes me think that there must very little variance between > the languages if THIS is the issue that deserves scrutiny. For the record: this is not the issue that deserves scrutiny. The other issues are more significant. However this "short array syntax" is representative of PHP's sluggish internal development process. [] is very nearly the de-facto solution for creating arrays, and yet the PHP core devs have, for two years, rejected[1] patches that implement it on ridiculous grounds. [1]: https://wiki.php.net/rfc/shortsyntaxforarrays https://wiki.php.net/rfc/shortsyntaxforarrays
- Androsynth 15y agoThis is one thing that really bugs me about the arguments against php. The language has fundamental flaws. Poor oop, no functional programming whatsoever, minimal reflection. Finding the argument order for a method takes ~3-5 seconds. Its irrelevant. array() vs [] is actually a bigger deal as its indicative of php's verbose syntax. But its not a killer. People like JS because it got the fundamentals right. The bad parts are just details. PHP is bad because it got the fundamentals wrong. But people still harp on the details.
- generalk 15y agoYes, PHP has fundamental flaws. But the only decent fix for that is to use a different language, and there may be many valid reasons why a developer is using PHP. But the "details" grate daily. Poor reflection, no FP? Fine, you craft solutions that don't require them. But having to look up order of arguments for standard library functions is a pain in the ass.
- eropple 15y agoNo functional programming whatsoever? PHP 5.3, which certainly does provide that, is more than two years old. (And it also introduced late static binding and a few other tweaks and benefits to make its OOP significantly better.)
- user24 15y ago> Arrays are created with array() as opposed to a more modern []. What? Why is [] better? Because it saves you typing 5 extra characters?
- DanHulton 15y agoHonestly? Yeah. The 5 characters adds up, typing it over and over, and stylistically, it looks nicer. A lot of little details make a big difference.
- SeoxyS 15y agoNot to mention, some of the functions return an array, and some of the functions act of the array passed as argument. Unless you remember exactly, you'll constantly be checking the doc to verify the method does what you think it does.