Jump to content

unset question


Liquid Fire

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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