Coding Syntax
by
30 Aug 2002
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')
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"]))
When reffered to there should be no spaces between the name and the parameters being passed in. PHP Code:
imaginary_function($var, $rank);
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)
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. |