Take the 2-minute tour ×

What does the double underscores in these lines of PHP code mean?

share|improve this question
add comment

4 Answers

up vote 33 down vote accepted

Looks like you're using Wordpress - wp-includes/l10n.php defines __ as a function that translates a string (similar to gettext and its alias, _ but with an optional parameter for explicitly specifying a domain).

share|improve this answer
Is it just me or is that hideous? –  Benji XVI Nov 22 '09 at 1:42
It's not just you. It's hideous. –  jrtayloriv Apr 13 '11 at 7:28
Hideous, but very convenient. As a sidenote, php.net says that all functions starting with __ (double underscore) are reserved. It sounds like they don't like the fact that WordPress and others are poaching on their magic method territory. us.php.net/manual/en/language.oop5.magic.php –  Lane Feb 20 '12 at 18:52
add comment

Strictly speaking, it means nothing in PHP as it is not a pre-defined function. However, in many frameworks, like CakePHP, and other libraries the double underscore is a function used for translating strings based on the user's language/locale preference.

share|improve this answer
No idea. Confusingly though, the CakePHP version of __ behaves completely differently to the one in Wordpress (CakePHP, by default, echoes the string unless the second parameter is false). I'll bet that never tripped anybody up before... –  SimonJ Nov 22 '09 at 2:01
add comment

As mentioned it is generally used for translating text between languages but really it is used in the same context as any function call.


is no different then

share|improve this answer
Actually, testfunction() is very different, because it has a sane name. __ is a completely stupid thing to name a function. –  jrtayloriv Apr 13 '11 at 7:30
add comment

A similar or third-party GNU gettext based implementation:


Note: You may use the underscore character '_' as an alias to this function.

share|improve this answer
add comment

Your Answer


