Solved

What is __( in php

Posted on 2010-09-09
8
431 Views
Last Modified: 2013-12-13
I saw this on a php script, what does that mean (two underscores) ?

__('Read the rest of this page')

0
Comment
Question by:sahanz
8 Comments
 
LVL 8

Expert Comment

by:kumaranmca
ID: 33643417
Greetings sahanz,


__ its magic methods..

Refer the below url...its main future of PHP5

http://php.net/manual/en/language.oop5.magic.php

more methods availbale..like __call, __get...
0
 
LVL 3

Accepted Solution

by:
jchook earned 250 total points
ID: 33643704
__('This is used for internationalization in WordPress');

Internationalization (abbreviated i18n (see http://en.wikipedia.org/wiki/Internationalization_and_localization)) is a way of providing translations for the text on a website or other software.

Developers wrap all of the various chunks of text for a website or application in the simple function __. Then, translators can create language files that literally map specific phrases from one human language to another.

So, for example, if your website code has __('The Example'); written somewhere, and the language flag is set to French, the page will display 'L'exemple' instead of 'The Example', so long as there is a French language file that correctly connects the two.


However, this may not always be the case.

In PHP, you can define the function __ to do anything you want. For example:

function __($a) {
  return strrev($a);
}

The function above will reverse any string.

print __('hello'); // outputs olleh
print __('racecar'); // outputs racecar


The short answer is: It is entirely based on context.
0
 
LVL 14

Expert Comment

by:Dushyant Sharma
ID: 33643984
PHP automatically creates variable and assigns values to it even is the variables are not defined. But in Object Oriented Programming all the data members/methods needs to be defined.

Magic methods are used to solve this problem. PHP reserves all function names starting with __ as magical.

These methods for overloading purpose. Please refer http://php.net/manual/en/language.oop5.overloading.php
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 33645591
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 33653052
Double underscores are reserved by PHP, and apparently used in a quirky (possibly conflicting and dangerous) way in WordPress.

Single underscores get used in Drupal.

So the executive summary is, if you have PHP don't name anything starting with a double underscore.  And if you have a CMS don't name anything starting with an underscore.
0
 
LVL 1

Author Comment

by:sahanz
ID: 33680682
Btw this is not a magic method right?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 33681189
Please see this page:
http://php.net/manual/en/language.oop5.magic.php

HTH, ~Ray
0
 
LVL 1

Author Closing Comment

by:sahanz
ID: 33681250
Thank You
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
converting numbers with php 3 31
How to keep line breaks when outputting data from database 4 14
PHP: concatenate query 13 44
Scope of $_SESSION 17 30
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now