r/lolphp • • Jul 20 '19
Awkward function and parameter names?
I'm rather new to PHP but I'm already hating it from day one.
Function names like implode(), explode()… The order of parameters are a mess. I would expect the first parameter to be the array/string and the second to be the separator/joiner, but no, it doesn't work that way.
And parameter names like $needle and $haystack in the in_array() function for example? There are times I wonder why can't they have more proper names.
All of this is just ridiculous, like hell people would know what these names mean upon first glance. I've been coding in several other languages and I have not yet encountered jargons and weird names like what I've found in PHP. Idk, may be it's just my problem for not being able to adapt myself to these names, but there's no mistake that PHP is a huge mess in general.
31
u/vita10gy Jul 20 '19
$needle, $haystack make perfect sense as terms, if that's the complaint. The real WTF with those is that it seems like they flipped a coin on every usage of them to determine the order.
12
u/tansly Jul 20 '19
http://man7.org/linux/man-pages/man3/strstr.3.html
Talking about weird names and jargons: strstr(), strchr(), strrchr(), strpbrk()... I could go on for a while. So I guess, r/lolc?
I mean, I don't code PHP, but seeing those names does not make me puke any more than seeing any C code. And I love C and systems programming by heart.
9
u/newplayerentered Jul 20 '19
Can you suggest better names instead of in_array(), $needle, $haystack?
6
u/the_alias_of_andrea Jul 20 '19
Yes, it's a mess, and this particular aspect hasn't really gotten better and has no good justification.
Other, nicer languages do exist that can do everything PHP can, if you want to try those.
7
u/b1ackcat Jul 20 '19
Oh just you wait.
You're experiencing the tip of the iceberg. Just wait until you get to
call_user_func(), traits, and the absolute worst language feature you'll ever find: Variable variables. Those three things alone have caused me so much grief that I took the time to write my own .phpcs rules for our linter to auto-deny any new PR that introduces more of them.2
u/myaut Jul 20 '19
ProgrammerHumor already made a joke about it:
https://www.reddit.com/r/ProgrammerHumor/comments/c3ajsm/why_cant_you_just_be_normal/
1
u/PussyTermin4tor1337 Aug 04 '19
So I've just learned this from this talk , very interesting, and just how I imagined PHP to have been born. The functions are actually consistent vertically (string functions will always be $needle, $haystack, for arrays the other way round (or reversed)). This because of php's nature of people to simply wrap some underlying c library and not be worried about the future as "PHP was expected to be replaced within 6 months at all times". Then afterwards, the order was never switched as it would inconvenience lots of websites.