views:

783

answers:

5

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

$WPLD_Trans['Yes']=__('Yes',$WPLD_Domain);
$WPLD_Trans['No']=__('No',$WPLD_Domain);
+10  A: 

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.

Mike B
Why the downvote?
Mike B
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
+5  A: 

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).

SimonJ
Is it just me or is that hideous?
Benji XVI
A: 

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

testfunction();

is no different then

__();
jasondavis
A: 

A similar or third-party GNU gettext based implementation:

http://www.php.net/manual/en/function.gettext.php

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

knoopx
A: 

Double underscore is a reserved word for compilers (of the C++ type, such as Perl). You can find references to this fact by searching for "variable name conventions underscore" on google.

djangofan