Liquid Fire Posted March 11, 2008 Share Posted March 11, 2008 Is: $varaible = new object a(); $variable = null; The same as: $varaible = new object a(); unset($variable); $varaible = null; I just wonder in PHP automatically changes the size of a variable since object a could be much larger then null or so i have to unset to free up the memory. Quote Link to comment Share on other sites More sharing options...
trq Posted March 11, 2008 Share Posted March 11, 2008 In the end $variable equals NULL either way, so no, theres no difference. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 11, 2008 Share Posted March 11, 2008 No. unset destroys the variable. defining it as null maintains the variables existence. Though I don't think it makes a difference beyond memory consumption. Most functions that check if a variables exists (isset(), empty() ect..) will return the same whether null or unset() is used. The memory difference between unset($var); and $var = null; is incredibly minimal, and i wouldn't be too concerned unless you're doing something on an utterly massive scale Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted March 11, 2008 Author Share Posted March 11, 2008 No. unset destroys the variable. defining it as null maintains the variables existence. Though I don't think it makes a difference beyond memory consumption. Most functions that check if a variables exists (isset(), empty() ect..) will return the same whether null or unset() is used. The memory difference between unset($var); and $var = null; is incredibly minimal, and i wouldn't be too concerned unless you're doing something on an utterly massive scale Well this is for a framework i am building so i guess i will use the unset instead if = null or = array() or etc... Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 11, 2008 Share Posted March 11, 2008 unset is best practice. Quote Link to comment 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.