Solved

What is __( in php

Posted on 2010-09-09
8
433 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 33645591
0
 
LVL 109

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 109

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 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