Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double Underscore in PHP?

Tags:

syntax

php

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

$WPLD_Trans['Yes'] = __('Yes', $WPLD_Domain); $WPLD_Trans['No'] = __('No', $WPLD_Domain); 
like image 396
Drahcir Avatar asked Nov 21 '09 23:11

Drahcir


People also ask

What __ means in PHP?

__ in PHP is for magic methods like __get , __set , __clone. Historically _ before variable or function means it's private since there was no private, public or protected methods in PHP 4 . It is applied not only to PHP . In Python for example, _ prefix for functions and variables is used for the same purpose.

What starts with __ double underscore in PHP?

PHP functions that start with a double underscore – a “__” – are called magic functions in PHP. They are functions that are always defined inside classes, and are not stand-alone functions.

What does the underscore do 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.

What is double underscore in laravel?

@froedrick double underscore is translation of the text. So, if you want to use multiple languages - you'll be able to easily define translations for this text. By default (if no translation defined for the current language) it will displays text as it is. 2. Level 50.


1 Answers

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

like image 100
SimonJ Avatar answered Sep 18 '22 13:09

SimonJ