Solved

What is __( in php

Posted on 2010-09-09
8
435 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

729 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