Anyone know what the _() function does?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Anyone know what the _() function does?

Post by flying_circus »

Admittedly, I didnt search high and low, but I discovered the _() function today. Punching it into php.net docs brings up "About the Manual" section of the documentation.

Code: Select all

<?php
  print _();
?>
The above code returns: "Warning: _() expects exactly 1 parameter, 0 given in test.php on line x";

Given a parameter, it just seems to echo the string back.

Meh, more curious than anything.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Anyone know what the _() function does?

Post by Darhazer »

It's defined by the gettext extension

Code: Select all

<?php
$ref = new ReflectionFunction('_');
var_dump($ref->getExtension());

Code: Select all

object(ReflectionExtension)#2 (1) { ["name"]=> string(7) "gettext" }
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Anyone know what the _() function does?

Post by Jenk »

http://www.php.net/_
Note: You may use the underscore character '_' as an alias to this function.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Anyone know what the _() function does?

Post by josh »

Naming translation functions with underscore is just kind of an unspoken tradition. It lets you do things like:

echo $this->escape( _('My Text') )

(keeps it as short as possible)
Post Reply