Hacker News new | ask | show | jobs
by duncan-donuts 2325 days ago
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

4 comments

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.