Maria Teresa notation for PHP

Maria Teresa notation for PHP (also known as MT notation) is intended to help developers with the programming style of the variables in PHP.
As the type hinting of PHP is weak, the notation helps to identify bugs by seeing, with the prefix, what kind of variable was it intended for.

It is inspired by the old and useful Hungarian notation.

I would like to credit and to show gratitude to a great person and developer, that passed away many years ago, and who shown me for the very first time the advantages of using prefix notation when coding, long time ago much before PHP appeared. In loving memory of Emilio.

Specification v. 1.1. Last modified 2014-03-30

The names have to be significant, so auto-descriptive.
Do not use $k or $i even for loops.
Use $i_loop $i_counter $i_num_person etcetera instead.

It recommends some prefixes:

Variables that are intended to used publicly, or used inside many methods and functions with global will start with:

$p_

Like:

$p_st_config = Array('database' => '127.0.0.1',
                     'username' => 'db_web',
                     'password' => 'mypassword'
                    );

Other prefixes:

Prefix Type of variable
$s_ String
$i_ Integer or numeric in general if you don’t use $f_
$f_ Float. Optional use
$b_ Boolean
$st_ Array, general use if you don’t use $a_ and $h_
$a_ Array with keys numeric. Optional use
$h_ or $d_ Array hash / Dictionary, with keys string. Optional use
$o_ Object or Recordset

Class names in Camel Case and Constants in Uppercase. Like:

class Db
{

    const TYPE_CONNECTION_MYSQL             = 'mysql';

    const SERVER_LOCALHOST                  = 'localhost';

    const CONNECTION_METHOD_UNIX_SOCKETS    = 'unix_sockets';
    const CONNECTION_METHOD_TCPIP           = 'tcpip';

    const PORT_DEFAULT_MYSQL                = 3306;

Some samples:

$i_start_time = microtime(true);

if (Navigation::isURLCustom(REQUESTED_PATH)) {
    // custom url
    $b_custom_url = true;
    $s_html = $o_controller->$s_action(REQUESTED_PATH, $o_db);
} else {
    // MVC pattern
    $b_custom_url = false;
    $s_html = $o_controller->$s_action(REQUESTED_PATH, $st_params, $st_params_url, $o_db);
}

$i_finish_time = microtime(true);
$i_execution_time = $i_finish_time-$i_start_time;

$o_controller->sendHeaders();

As you can see $i_start_time was created to be of the type Integer, $b_custom_url is a Boolean, $s_html of the type String, $o_controller is an object, and ->$s_action(REQUESTED_PATH, $o_db); is a string variable that contains the name of the method to invoke (we use variables variable) while the parameter REQUESTED_PATH is a Constant and $st_params is an Array and $o_db is an object.

The MT notation can also be used to build SQL queries. It is specially useful for locating errors quickly in JOINS (like comparing VARCHAR and INT) and in Stored Procedures.

Views: 8,563 views

1 thought on “Maria Teresa notation for PHP

  1. Pingback: A quick note about symmetric encryption and entropy | Carles Mateo


Rules for writing a Comment


  1. Comments are moderated
  2. I don't publish Spam
  3. Comments with a fake email are not published
  4. Disrespectful comments are not published, even if they have a valid point
  5. Please try to read all the article before asking, as in many cases questions are already responded

Leave a Reply