What is the purpose of this implementation?
I believe you’re referring to the use (unset) $var. This form is related to the typing of the variable, as well as (int) $var, or (string) $var... the use of (unset) $var will change the type of the variable to null.
Casting a variable to null using (unset) $var will not remove the variable or unset its value (DOC)
$var = NULL would no longer be enough?
There are times when you may need to destroy a variable and not simply have it null, and when using $var = NULL, $var will continue to exist. However, to change guy, yes, $var = NULL could be sufficient since it has the same effect as (unset) $var.
However, if you maintain a standard for typing, the use of (unset) $var may be more convenient than $var = NULL, because in the second case you are changing the type assigning a new value, rewriting the variable.
An example:
#1
$var = (int)'123'
#2
$var = 123
In both my cases $var is an int type. In the first I forced string typing to integer and in the second it assigns an integer value.
Is there any case where the use of (unset)?
About this there is much explanation in itself DOC function, but I don’t know if you refer to typing (unset) $var or the removal of the variable with unset( $var ).
I don’t know if that’s exactly what you wanted to know. If need be I try to make an update.
From what little I understand and read in several blogs of PHP experts, most or almost all are unanimous in the use of unset for micro optimizations. I don’t have links now, but if you want to know more, search for "php micro Optimization unset" or something like that. I always use on all objects that will no longer be used during the script.
– Daniel Omine
Related: http://answall.com/a/23737/250
– Bruno Augusto