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. Link to comment https://forums.phpfreaks.com/topic/95631-unset-question/ 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. Link to comment https://forums.phpfreaks.com/topic/95631-unset-question/#findComment-489589 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 Link to comment https://forums.phpfreaks.com/topic/95631-unset-question/#findComment-489594 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... Link to comment https://forums.phpfreaks.com/topic/95631-unset-question/#findComment-489668 Share on other sites More sharing options...
discomatt Posted March 11, 2008 Share Posted March 11, 2008 unset is best practice. Link to comment https://forums.phpfreaks.com/topic/95631-unset-question/#findComment-489687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.