Due to the release of vB3 being around the corner (i like being vague ) I just thought I'd post some coding standards that
have been introduced.
Variables
They must have appropriate names to the data they contain if you've just selected data from the user table don't call it
$stuff or anything like that.
When your reffering to any information passed in by the user use $_REQUEST['variablename'] or $_POST['variablename'] instead
of $variablename, some nice register_globals off compliance.
Basic Syntax
Use tabs to indent the line, this should be done everytime you open a new set of parenthesis and will continue until the closing parenthesis.
Parenthesis should be on a new line of there own like below
PHP Code:
if ($_REQUEST['do'] == 'var')
{
$var = 'test';
if ($bbuserinfo['usergroupid'] == 6)
{
echo 'your an admin';
}
}
If you are using if or elseif, make sure there is a space between that and the comparison.
Use singlequotes from now on where possible, you will not be able to do this when you have a variable in the string as this
will not be evaluated with the string. This includes keys in arrays, unless the key is another array you would use the second example in the following code.
PHP Code:
if (empty($array["var"]))
{
echo 'blah';
}
//CORRECT USAGE
if (empty($array['var']))
{
echo 'blah';
}
//if you are referring to the key by another array use
if (empty($array["$array2[var]"]))
{
echo 'blah';
}
Functions
When reffered to there should be no spaces between the name and the parameters being passed in.
PHP Code:
imaginary_function($var, $rank);
When passing in parameters to a function ensure that you have spaces between the comma and each variable being passed in.
Depreciated Functions
It was common to see the following in vBulletin 2, the second version is what will be used in vBulletin 3.
PHP Code:
if (isset($action) == 0)
{
$action = 'modify';
}
//USE THIS INSTEAD
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'modify';
}
Expressions
With an if expression where you are comparing two or more items use OR and AND, not || and &&. This is simply due to the fact that its easier for the human to read.
I know i've forgotten stuff and I will add more as I can think of it.
Hopefully this will improve coding in general when your not using vBulletin and writing your own scripts.
PHP 4.0.6 was set at the minimuim as its the latest secure version you could have, as php.net provides a patch for php 4.0.6 to patch the upload security holes.
Originally posted by PPN Basic Syntax
Use tabs to indent the line, this should be done everytime you open a new set of parenthesis and will continue until the closing parenthesis.
Parenthesis should be on a new line of there own like below
PHP Code:
if ($_REQUEST['do'] == 'var')
{
$var = 'test';
if ($bbuserinfo['usergroupid'] == 6)
{
echo 'your an admin';
}
}
Scott, can you please explain to me why this approach? i think this will only slow down the code writing process.
first, it takes alot longer to code using this technique.
second, the file will be huge in leght.
third, is a waist of time for every time you press an extra Enter.
i will not upgrade anyway to VB3, for a while. not until 3.1 or 3.2 is released.
It was done so that the coding is more spaced out so you can see and understand the code more clearly. It also is better for editors which support brace matching like Komodo and TextPad
Originally posted by PPN PHP 4.0.6 was set at the minimuim as its the latest secure version you could have, as php.net provides a patch for php 4.0.6 to patch the upload security holes.
Uhmmm Does 4.06 supports these kinds of arrays? $_REQUEST, $_GET, $_POST, etc?