ollie007 Posted June 10, 2009 Share Posted June 10, 2009 when do you unset a variable? if it s loating around can it be overriden? or does it get lost and locks up? Quote Link to comment https://forums.phpfreaks.com/topic/161616-when-to-unset-a-variable/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 10, 2009 Share Posted June 10, 2009 All resources used in the php code on any page get destroyed when that page ends execution. Within the php code on any page you can reuse variables any way you like. You would only specifically unset them if you needed to free up the memory used by them or if your application needed your to unset them for logical reasons later in the code on that page. Quote Link to comment https://forums.phpfreaks.com/topic/161616-when-to-unset-a-variable/#findComment-852813 Share on other sites More sharing options...
RussellReal Posted June 10, 2009 Share Posted June 10, 2009 as PFM says, all data is destroyed when the script exits, minus sessions, they are stored in a file somewhere on teh computer with the unique session ID for that session. Variables arn't exactly 'floating' around, they're exactly where you need them, there are two main reasons you'd unset a variable, 1) You have an if statement which checks for 'isset($whatever)' and you could have a certain procedure to check whether or not to actually unset $whatever or not due to other factors, but that is bad practice, you should use booleans for that. 2) You are handling alot of data, and to avoid your script producing an error and dying, you should free up memory as you progress in the script Quote Link to comment https://forums.phpfreaks.com/topic/161616-when-to-unset-a-variable/#findComment-852840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.