Jump to content

variables assigments


jimfog

Recommended Posts

To stick with as few variable names as possible I do this-not unusual:

 $address=trim($_POST['address']); $address=filter_var($address, FILTER_SANITIZE_STRING);

The value of the address variable changes of course from one line of code to another.

 

Do you think there are negatives to the above coding scheme,using variables that way?

 

I just do in order not to mess with many variable names.

Link to comment
Share on other sites

there is another side of the coin to consider in programming, and that is readability. These days, the benefits of trying to be as compact and trying smash things into one line aren't really necessary, so it doesn't hurt to spread things out so it's easier to read and follow what the code is doing.

Link to comment
Share on other sites

there is another side of the coin to consider in programming, and that is readability. These days, the benefits of trying to be as compact and trying smash things into one line aren't really necessary, so it doesn't hurt to spread things out so it's easier to read and follow what the code is doing.

You did not say anything about my code. Is it a good practice to have the same name variable and just change its value where necessary.

Link to comment
Share on other sites

If you're doing multiple string manipulations, it's probably best to use the same variable for it. Each variable is a pointer to a different space in memory, if you used different variables you'd have pieces of memory with half-processed strings that would remain there until the garbage collector came around.

 

I wouldn't recommend using the same variable name in two separate parts of the program because you might accidentally overwrite a value you needed.

Link to comment
Share on other sites

Υou are clear now...thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...