Kami's Corner

Bearblog Carnival: My favorite PHP function names

Heya!
So, when i made the post announcing that i was hosting the bearblog carnival for this month a couple days back, i said I was gonna talk about my favorite PHP function names. So, here's that post!

Now, before we get started, I want to talk about why I can even make a blogpost about this. Because, the reason I'm writing is is that much of php early functions are named in very, very strange ways. And there's a reason for that! Not a good reason, but there is one.

So, long story short: When you call a function in a programming language, it needs to check what that function does. To do this, it needs to search for the function. And to speed up that process, early PHP had a bunch of different buckets of functions. It would first determine which bucket to search, and then search for your function only inside that bucket, which would be a smaller subset of all the functions in PHP, so it would take a shorter amount of time.

For this system to be effective, you would obviously need all the functions to be evenly distributed across those buckets. So, what did PHP choose as criteria for which function goes in which bucket? Well, the length of the name! Yes, for some reason that's what they went with. This means, that in very early versions of PHP, the language would get more inefficient at calling functions the more functions you had whose names were the same length.

So, what did they do to combat this? Fix the algorithm? Well, that's what they did eventually - this is no longer a problem in any PHP version anybody is actually using. But for a while, the solution was to simply just... Name functions weird things so they go into a different length bucket. So, that's why PHP has a bunch of really weirdly named functions. They're remnants of this weird function sorting algorithm. Well, that's only one reason why, there's a couple different things that also influenced this, but this is the funniest contributing factor.

Anyways, without further ado, let's go look at some stupid function names!

Implode / Explode

I think these are by far my favorite function names out of the ones that I actually use. They're used for joining together or splitting up text. Other languages might call these functions something boring like join() and split(), but not in PHP. When we wanna split up text, we blow it up! Or... implode it when joining it together. Which doesn't seem like the best metaphor for that operation now that I'm thinking about it. But who cares! Look at all the awesome explosions!

mysql_real_escape_string and mysql_escape_string

Alright, so first of all: Don't use either of these functions. They're ancient at this point, and mysql_escape_string doesn't even exist anymore.

So, both of these functions are used to escape mysql strings. Basically, they're used to prevent your users from injecting arbitrary instructions into your database and potentially deleting all your stuff or leaking a bunch of private user data.

Anyways, what's the difference between the two? Well... There was actually a security issue in mysql_escape_string. So, what do you do? Well, add another function of course! What, you think we should fix security vulnerabilities? That would break backwards compatability!

Anyways, although php kind of gets dragged for this a lot, and while it is very funny, this wasn't actually php's fault. Both of these functions are just straight 1:1 wrappers for the equivalent functions in the mysqli C library. So, blame those guys i suppose. Nowadays PHP has PDO to handle all of this, which is a much better database driver anyways. Still, it's a funny historical relic.

metaphone

This function is, suprisingly, quite aptly named. It implements the metaphone algorithm, so its called metaphone. What does the metaphone algorithm do? It tells you how similiar sounding two english words are! And only english words! Doesn't really work with any other language! Why would you use this? I don't know! There's probably some practical application. But what eludes me is why it's part of PHP's ""standard library""1

chop

This removes all whitespace from the end of a string. I mean, sounds reasonable enough, right? Not too weird of a name, we've seen worse on here.

Well... This isn't a real function.
I mean, it is in the sense that you can call it and it will do what i previously described, but in reality it's a completely obsolete wrapper around the function rtrim().

It doesn't actually do anything, it just calls that function. My best guess for why this exists is because the programming language pearl has a similiar function thats called the same thing. So like, to make it easier for pearl programmers to use the language? But also, PHPs rtrim doesnt really work like pearls chop, so this only serves to confuse those people.

Gender\Gender::__construct

Yep, PHP says gender is a construct! Well, alright, not really. This is just the constructor function for PHPs gender class. It's what gets called when you first create a gender object.

Wait a second, why does PHP have a gender class. And adding onto that, why does said class not only contain classics such as "IS_FEMALE" and "IS_MALE" but also "SPAIN", "PORTUGAL" and "SWEDEN"?

Well, this is actually a class for deciding the gender of a name. That's still a rather pointless endeavour since you can't really do that with any degree of accuracy though. Also why would you want to do that. Anyways, no matter what you think of how useful this may or may not be, im pretty sure the internal lists it uses no longer even get updated. So... Uh, I mean i guess you can use this one still but why would you.

die

Yep, there's a php function called die(). We're continuing the trend of simply being more hardcore than other languages by naming our functions cooler things. Except, die() is really just an alias for the much more polite sounding exit() function. Why does it exist? Who knows! It's one letter less though, so that's nice.

T_PAAMAYIM_NEKUDOTAYIM

Alright, this is one is kind of cheating because it's not a function. Instead its a variable! What are the contents of this variable? Well, its "::", of course! What, you didn't know that the hebrew name of that combination of characters was Paamayim Nekudotayim? Well, now you do!

So, why does this even exist? Well, it was used internally by PHPs interpreter to represent that symbol. The reason it's in hebrew is actually because fairly early on in PHPs development, large parts of the language were rewritten by two guys called Zeev and Andi. And they happened to be from Israel, so some of the internal names for stuff were in hebrew.

The variable was later renamed to T_DOUBLE_COLON around 2020. It used to actually be quite confusing, because if you were missing double colons in your code, the PHP interpreter would tell you that you had an error related to T_PAAMAYIM_NEKUDOTAYIM. Which, most people obviously don't know what that means. So, while a neat bit of history, im very glad this is no longer really a thing.

Aaaand, that's all the weird php functions we've got time for today! There's a lot more weird things PHP does that I could be talking about, but I'm just about out of interesting function names. Maybe I'll make another post like this going into odd non-naming related PHP things. There's a lot of funny stuff here.

  1. Well, technically PHP doesn't actually have a standard library. Well, i mean, i guess it does, but not really. A lot of functions people would consider to be part of PHPs standard library, and effectively are, are actually part of optional modules that get compiled into PHP. It's just that there's some modules that basically every distribution of PHP ships with. This has the fun side effect of the same numbered version of PHP having different built-in functions available depending on where you download it from. ...Just, don't think about it too hard.