0

what is "_" in php, and why it's a valid function when it's not defined.

# code will pass that check. and it will print "_"
if(function_exists("_"))
{
    print f('_');
}

also when i try to print ( it works, but gives me Notice )

print _;

php give me Notice.

Notice: Use of undefined constant _ - assumed '_'

so i used constant function and try to get his value,

print constant("_");

but what i get is

Warning: constant() [function.constant]: Couldn't find constant _ in

what i'm doing wrong here ?

Akshay Deep Giri
  • 3,139
  • 5
  • 25
  • 33
  • 1
    Also, with php.net, you can go to www.php.net/{any built-in function/class} and it will show you the docs for that function. If it is not found, it will search the php docs for that function. for example: http://www.php.net/_ – Jonathan Kuhn Mar 28 '13 at 21:32

2 Answers2

4

The _ function is a shortcut for gettext, a translation function. http://php.net/_

print _; prints the constant _, while print _(); would show you the output of the _ function (an error, when called with no arguments).

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
3

Because _() is a valid function,

It is used for localization.

when you just print _ you are trying to print the constant, adding the brackets () makes it a function call.

Your function_exists check should have told you that!

http://www.php.net/_

Hailwood
  • 89,623
  • 107
  • 270
  • 423