Page 1 of 1

T_ Prefix

Posted: Fri Oct 13, 2006 12:04 am
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

Posted: Fri Oct 13, 2006 1:24 am
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 ;)

Posted: Fri Oct 13, 2006 5:41 am
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/_