Jump to content

Initialize variables?


Azu

Recommended Posts

If my code is running fine without initializing variables, should I just leave it as is, or is there a benefit to initializing them?

 

Also, which way is best to initialize? $a=$b=$c=''; or $a='';$b='';$c=''? Or is there a better way then both of these?

Link to comment
Share on other sites

The best programming practice, I personally believe is to define ALL my variables at the top of the script like so:

 

$username = '';//this will hold the username for the current user
$site_to_check = '';//this will hold the page the user was just one
$ip_address = '';//this holds the true/false statement if the user's ip address was banned or not

 

So I look at the top of my script, see all the variables, and I can almost always recognize what page I'm looking at or what each variable is meant to hold... Cause I often have those memory lapses where I forget everything I coded that night and such and such :-P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.