Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
Coding Syntax
Scott MacVicar
Join Date: Oct 2001
Posts: 1,199

PHP, Perl and gaming

Glasgow, Scotland
by Scott MacVicar Scott MacVicar is offline 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


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Functions
When reffered to there should be no spaces between the name and the parameters being passed in.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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.

Last edited by Scott MacVicar; 28 Sep 2002 at 11:31..
Views: 4053
Reply With Quote
Comments
  #2  
Old 31 Aug 2002, 17:57
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
wow PPN thanks alot now i can see some light as to why vb3 will be in fact diferent thanks for sharing the very useful information... regards...

g-force2k2
__________________
Custom vBulletin Hacker => Making Ideas Into Working Programs => No Idea Can Ever Be A Bad Idea
--
My vb3 Hacks
--
[ Posting Required Before Poll Voting ] | [ vb3 Font Color Hack ] | [ vb3 User Forum Activeness Hack ] | [ vb3 Postbit Style Option ] | [ vb3 User Ratings Hack ]
Reply With Quote
  #3  
Old 31 Aug 2002, 17:59
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Everything is more or less coded to a standard, anything thats not will get changed eventually.
__________________
Scott MacVicar
vBulletin Developer
Reply With Quote
  #4  
Old 31 Aug 2002, 18:03
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
i see around all the array stuff

ie ::


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

instead of the usual ::


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

i've read that the first one (that vb3 uses) is the correct way to do it then the second one... can you confirm that this is in fact true?

Also should we not use the second example anymore? regards...

g-force2k2
__________________
Custom vBulletin Hacker => Making Ideas Into Working Programs => No Idea Can Ever Be A Bad Idea
--
My vb3 Hacks
--
[ Posting Required Before Poll Voting ] | [ vb3 Font Color Hack ] | [ vb3 User Forum Activeness Hack ] | [ vb3 Postbit Style Option ] | [ vb3 User Ratings Hack ]
Reply With Quote
  #5  
Old 31 Aug 2002, 18:09
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Yep vB3 uses the first and it is correct, if you dont have any quotes then its an undefined constant, using the quotes indicates a string.

Added a bit about using 'and' and 'or' instead of || and &&
__________________
Scott MacVicar
vBulletin Developer
Reply With Quote
  #6  
Old 01 Sep 2002, 20:28
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
question PPN?

whats the difference btw using? the positioning of if?

ie ::


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

and


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

does that space make it more efficient or something?

And is this $_REQUEST and $_POST vars vb3 creations or are they standard with php? regards...

g-force2k2
__________________
Custom vBulletin Hacker => Making Ideas Into Working Programs => No Idea Can Ever Be A Bad Idea
--
My vb3 Hacks
--
[ Posting Required Before Poll Voting ] | [ vb3 Font Color Hack ] | [ vb3 User Forum Activeness Hack ] | [ vb3 Postbit Style Option ] | [ vb3 User Ratings Hack ]
Reply With Quote
  #7  
Old 01 Sep 2002, 23:42
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Em just cosmetic with the if, it looks nicer

its the PHP Super Globals http://www.php.net/manual/en/languag...predefined.php for $_POST and $_REQUEST.

Though $_REQUEST is used because its all input from the user.
__________________
Scott MacVicar
vBulletin Developer
Reply With Quote
  #8  
Old 03 Sep 2002, 14:17
Chen's Avatar
Chen Chen is offline
 
Join Date: Sep 2001
There are 7 super global arrays in PHP, as of 4.1.0:
$_GET - contains all information that passed in the address bar (or a form with get method)... used to be $HTTP_GET_VARS.
$_POST - contains all information that is passed through a posted form (if the form was using the post method)... used to be $HTTP_POST_VARS.
$_COOKIE - contains all cookie information... used to be $HTTP_COOKIE_VARS.
$_REQUEST - simply a merge of all three arrays above... new.
$_FILES - contains information about uploaded files... used to be $HTTP_POST_FILES.
$_ENV - all environment variables... new AFAIK.
$_SERVER - all server variables... used to be $HTTP_SERVER_VARS.

Note that in vB3 these arrays are NOT super globals, or at least you must not assume they are. You'll see why when you actually see the code in init.php.
__________________
Chen Avinadav
Formerly vBulletin.org Owner and Founder

chen@avinadav.com
Reply With Quote
  #9  
Old 28 Sep 2002, 06:55
DraX DraX is offline
 
Join Date: Aug 2002
Real name: Ron DeFreitas
This brings up a question... will vB3 still be compatible on servers running older versions of php?

Due to an operating system conflict (damned Sun Microsystems machines), I can't safely upgrade my version of php without the potential of breaking the control panel for the OS....

Is there a function to determine if the version of php supports the super globals, such as $_REQUEST and if not, to define it as a new global using $HTTP_GET_VARS['REQUEST'] (I think that was right... off the top of my head)?
Reply With Quote
  #10  
Old 28 Sep 2002, 08:19
JulianD's Avatar
JulianD JulianD is offline
 
Join Date: Jan 2002
Real name: Julian Muņoz
Yeah, it's one of my main concerns about vb3. What will be the minimun required PHP version to run vb3?
__________________
Julian D. Muņoz
Reply With Quote
  #11  
Old 28 Sep 2002, 11:29
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
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.
__________________
Scott MacVicar
vBulletin Developer
Reply With Quote
  #12  
Old 28 Sep 2002, 13:53
TECK's Avatar
TECK TECK is offline
 
Join Date: Dec 2001
Real name: Floren Munteanu
Re: Coding Syntax

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


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
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.
__________________
Floren Munteanu
Axivo Inc.
Axivo Community - Visit the forums to find out more about us
Why Queued - My personal blog
Reply With Quote
  #13  
Old 29 Sep 2002, 15:32
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
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
__________________
Scott MacVicar
vBulletin Developer
Reply With Quote
  #14  
Old 29 Sep 2002, 15:33
TECK's Avatar
TECK TECK is offline
 
Join Date: Dec 2001
Real name: Floren Munteanu
true... i use textpad and the ctrl+m is a great feature...
__________________
Floren Munteanu
Axivo Inc.
Axivo Community - Visit the forums to find out more about us
Why Queued - My personal blog
Reply With Quote
  #15  
Old 07 Oct 2002, 05:13
JulianD's Avatar
JulianD JulianD is offline
 
Join Date: Jan 2002
Real name: Julian Muņoz
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
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

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


New To Site? Need Help?

All times are GMT. The time now is 13:27.

Layout Options | Width: Wide Color: