Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles

Reply
 
Thread Tools
Coding Syntax
Scott MacVicar
Join Date: Oct 2001
Posts: 1,199

PHP, Perl and gaming

Glasgow, Scotland
Show Printable Version Email this Page Subscription
Scott MacVicar Scott MacVicar is offline 08-29-2002, 10:00 PM

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.
Reply With Quote
  #12  
Old 09-28-2002, 09:29 AM
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Location: Glasgow, Scotland
Posts: 1,199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #13  
Old 09-28-2002, 11:53 AM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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.
Reply With Quote
  #14  
Old 09-29-2002, 01:32 PM
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Location: Glasgow, Scotland
Posts: 1,199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #15  
Old 09-29-2002, 01:33 PM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

true... i use textpad and the ctrl+m is a great feature...
Reply With Quote
  #16  
Old 10-07-2002, 03:13 AM
JulianD's Avatar
JulianD JulianD is offline
 
Join Date: Jan 2002
Posts: 455
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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?
Reply With Quote
  #17  
Old 10-07-2002, 06:17 AM
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Location: Glasgow, Scotland
Posts: 1,199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

no but the way it works vbulletin 3 will create these arrays.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:51 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05912 seconds
  • Memory Usage 2,264KB
  • Queries Executed 21 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (5)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (6)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete