jimfog Posted September 26, 2013 Share Posted September 26, 2013 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 More sharing options...
thescientist Posted September 26, 2013 Share Posted September 26, 2013 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 More sharing options...
justsomeguy Posted September 26, 2013 Share Posted September 26, 2013 You can also condense those lines into this: $address=filter_var(trim($_POST['address']), FILTER_SANITIZE_STRING); Link to comment Share on other sites More sharing options...
jimfog Posted September 27, 2013 Author Share Posted September 27, 2013 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 More sharing options...
Ingolme Posted September 27, 2013 Share Posted September 27, 2013 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 More sharing options...
jimfog Posted September 27, 2013 Author Share Posted September 27, 2013 Υou are clear now...thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now