YES.
You are in the manual: link
(for a change, Portuguese are missing important pieces in the translation)
exit - Output a message and terminate the current script
Description
void exit ([ string $status ] )
void exit ( int $status )
Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called .
The highlighted part is more or less this:
Shutdown functions and object destructors are always executed even if you use exit
("Even used exit", because this occurs at the end of script anyway)
Summary: use exit
or its die
synonymous gives the script a "naturally" ending. All the resources are released (which is one of the reasons OOP in PHP is a waste of resources, every request has to recreate everything that is new class to use).
Another thing, unset
is not a normal thing to use in PHP. There has to be a very good reason for this, in very specific situations. Under normal conditions PHP, like most scripting languages, manages memory for you.
A valid use example of unset
is the one mentioned by colleague Jorge Matheus in the comments, when it applies to a variable of $_SESSION
. This is because it is no longer about memory, but about data that is normally written to disk, so that the next script will recover. It makes sense to clean, as it is something that PHP will write at closing, and if it is something not more desirable, you have no reason to preserve the information.
Still, it is worth observing about OOP made earlier, since an object persisted in session needs to be read from the file or DB, and de-serialized to become object again. >