Skip to content

mathiasgrimm/php_variable_prefix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

PHP Variable Prefix

I have been using this variables prefixes in order to better organize my codes.
This helps as well when doing any kind of code analysis through an automatet script/tool

Once I had a really nice task (was really nice indeed) to convert an existing system from php4 to php 5.3.
All was done using a combination of php and shell script with lots of regular expression.
Actually this was the time when I learned regular expression.

If we had followed some convetions with variables names, the task would be way easier.

Some people say that just a good name is enough but in this case we had many good names that leaded to very nice problems
Just to give some examples:

Good Bad Names:

<?php
$date = new TDate();
$date = '2014-09-27';

$today = new TDate();
$today = '2014-09-27';
?>

Now, this is the convetions I have been using:

a - array    - $aRow
b - boolean  - $bExists
o - object   - $oUser
m - mixed    - $mParam
s - string   - $sName
f - function - $fCallback
r - resource - $rFile
i - integer  - $iId
d - double   - $dPrice
<?php
$aRow      = [1, 2, 3];              // a - array 
$bExists   = true;                   // b - boolean 
$oUser     = new User();             // o - object
$sName     = 'Mathias Grimm'         // s - string 
$fCallback = function(){echo 'hi';}  // f - function 
$rFile     = fopen('file.txt', 'r'); // r - resource 
$iId       = 12312312;               // i - integer 
$dPrice    = 10.99;                  // d - double 

// m - mixed
function foo($mParam) 
{

}

foo(['name' => 'Mathias Grimm', 'site' => 'phpEmpregos.com' ]);

$oParam       = new stdClass();
$oParam->name = 'Mathias'

foo($oParam);
?>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published