php: better way to name variables - because you want to be understood
2009-07-21 09:22:29
IN1
,
2023-07-25 21:09:34
IN1
I would like to share how I have been naming variables for many years: camelCase prefixed with a leading letter, which gives a hint about the data type.
This style resembles the so-called Hungarian notation
, but not completely.
boolean
// leading $b for boolean type
$bSuccess = true;
integer
// leading $i for integer type
$iYear = 1969;
string
// leading $s for type string
$sName = 'Foo Bar';
array
// leading $a for array type
$aData = array(1, 2, 3);
object
// leading $o for type object
$oDTRequestCurrent = \MVC\Request::getCurrentRequest();
resource
// leading $r or $h for type resource
$rCurl = curl_init();
handle
// leading $r or $h for type handle
$hCurl = curl_init();
float
// leading $f|$d for float (double) type
$fPrice = 10.90;
$dPrice = 10.90;
mixed
// leading $m for mixed data
$mData;