Hacker News new | ask | show | jobs
by irrational 2329 days ago
One of the biggest complaints I've read about PHP is that many things are not consistently named (having never used PHP, I might be wrong). If this is true, are there any plans to fix this?
4 comments

It is true and no I don’t think there’s much talk of changing it. There’s also a problem with inconsistent method arguments. Just look at array_map[1] and array_reduce[2]. This is just the one example that bit me the most, but there are other inconsistencies like this all over the language that require you to constantly look things up.

[1] https://www.php.net/manual/en/function.array-map

[2] https://www.php.net/manual/en/function.array-reduce

Array map takes one or more arrays with a callback, so the arrays have to be on the end.

Array reduce has one array as a parameter, as does most of the other functions and they all have the array as the first parameter.

Its only one function, and its an inconsistency for a reason. Lets not blow it all out of proportion.

I remember reading a cogent explanation for this inconsistency but can't seem to locate it.

JavaScript suffers from inconsistent mutation/return of array values in array functions, too.

PHPs design problems are mostly being swept away; it's the legacy that keeps its reputation down.

Rasmus Lerdorf has talked about it in other videos but this is one https://youtu.be/iGOAQli7tGc?t=1485

Basically, groups of functions are consistent: string,array etc. Their parameter order was usually based on whatever the underlying C API was.

I use an editor that has the php help built in to not get confusing errors. You type the beginning of the command and it directly tells you what part is the needle and what is the haystack.
I just encountered this last week.

I had to explain to my fellow non-IT students why I was making loud gasps of confusion.

In practice it hasn't been a problem for me in a long time (I've been doing PHP since PHP3 so I have some perspective on it).

First the documentation is fine and easily accessible, second your IDE will hint you the correct order and finally in a real world web framework situation you don't even use those functions that much anyway.

My biggest complaint would in fact be the concurrency situation, it's still not easy and relies on external libraries that feel half-hacks. I guess Elixir spoiled me in that regard.

And when enabling strict types you will get an error anyway if you have the wrong order because the types will not match.
"My biggest complaint about this language I've never used is something I'm not sure is true. Is it?"
Well, I have worked as a web developer for 20+ years. I've heard that PHP is inconsistent dozens, perhaps hundreds of times. I've just never verified it myself since I've never used PHP.
Maybe the Hack language?