Solved

What is __( in php

Posted on 2010-09-09
8
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 33645591
0
 
LVL 110

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 110

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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