Jump to content

when to unset a variable?


ollie007

Recommended Posts

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.