I have a form with several fields that will be a fairly active. With that said there is a validation piece.
A user POST’s and the values are stored in $_SESSION variables.
On fail, the $_SESSION variables are cleared that are incorrect. I do this because the form echo’s back the previous values that are still correct, out of convience to the user.
Which is faster:
$_SESSION['variable']="";
PRO–>Less operations for each form POST
CON–>Server stores more $_SESSION variables at any given point.
unset($_SESSION['variable']);
PRO–>More operations for each form POST
CON–>Server stores less $_SESSION variables at any given point.
Thoughts?
You should
unset()as setting it to an empty string means the session variable still exists and is pointing to a location in memory.You shouldn’t worry at this stage which is faster, just think of what best communicates your code’s intentions.