Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does PHP's underscore function do?

Tags:

What does this function do?

_() 

Can you link me to the relevant documentation, as searching for "_" is nigh on impossible?

like image 836
JasonS Avatar asked Aug 05 '10 10:08

JasonS


People also ask

Why use underscore in PHP?

In PHP, the underscore is generally reserved as an alias of gettext() (for translating strings), so instead it uses a double-underscore. All the functions that make up the library are available as static methods of a class called __ – i.e., a double-underscore. …and so on.

Why are underscores used in C?

It's just an identifier, it's valid. You can use _ by itself as an identifier. that makes _ a variable of type int .

What is double underscore in PHP?

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.

What is__( in PHP?

The __() is just an alias for it. So __("some text") is equivalent to gettext("some text") edit: Actually if it's two underscores than it isn't gettext(). The alias for gettext() is one underscore.


2 Answers

If you open http://www.php.net/_ you get to the documentation of the _() function and see its for localization stuff (gettext).

like image 145
Progman Avatar answered Oct 11 '22 06:10

Progman


_() is an alias of gettext().

like image 33
gnud Avatar answered Oct 11 '22 06:10

gnud