Page 1 of 1

Anyone know what the _() function does?

Posted: Sun Jan 10, 2010 7:32 pm
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.

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

Posted: Sun Jan 10, 2010 7:54 pm
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" }

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

Posted: Mon Jan 11, 2010 4:27 am
by Jenk
http://www.php.net/_
Note: You may use the underscore character '_' as an alias to this function.

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

Posted: Mon Jan 11, 2010 7:15 pm
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)