Cleaning variables in PHP

There was already a similar question, but there was no answer to what I was interested in.

  • Why is this being done if the garbage collector will clean everything up anyway?
  • As far as I remember, there is a whole mechanism for freeing memory that kills processes (for example, FastCGI) and starts them again. It seems that if this is not done, then the memory overflows. Is clearing variables a way to reduce the number of worker restarts?
  • Does it give any performance bonus? (addition to question 2) or is using this mechanism faster than manual cleaning?
  • In terms of security, does it make sense to clear a variable as soon as it is no longer needed?
  • What happens to a variable after unset? Does isset return false?

It seems to be all for now, if new questions appear, I will add them to the list.


Answer 1, authority 100%

Why is this being done if the garbage collector will clean everything up anyway?

Generally speaking, rarely used. I don’t remember when I last used it. Well, except for arrays – to remove elements

Is clearing variables a way to reduce the number of worker restarts?

No. In FastCGI mode, the interpreter is re-initialized each time, so you don’t need to bother here at all.

In terms of security, does it make sense to clear a variable as soon as it is no longer needed?

Honestly, I don’t understand what security has to do with it

What happens to a variable after unset? Does isset return false?

Yes