T_ Prefix

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pastijalan
Forum Newbie
Posts: 10
Joined: Thu Oct 12, 2006 11:54 pm

T_ Prefix

Post by pastijalan »

Hi Guys, I know this is a stupid question. I often see T_ prefix used in php code , for example:

die(T_('message_die() was called multiple times.'));

$debug_text .= '<br /><br />'. T_('SQL Error') .' : '. $sql_error['code'] .' '. $sql_error['message'];



What exactly does the T_prefix do?.

Thx
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

In PHP's own error reporting you'll see it. I'm not sure who'd use it for an SQL error as that would not make much sense.

PHP will use T_... for syntax errors where the parser failed to tokenize code. T is for "token".

Source code is broken down into small chunks called tokens when PHP starts to parse it:

Take the code:

Code: Select all

<?php

class Foo
{
    
}
PHP turns it into something like:

1. <?php
2. class
3. Foo
4. {
5. }

Each of those tokens have a name like T_PHP_OPEN, T_CLASS, T_STRING etc

These are the names you see in errors ;)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

There's also a function called T_ in b2evolution, http://doc.b2evolution.net/v-0-9/evocor ... e.php.html
similar to http:/de2.php.net/_
Post Reply