What is the purpose of this implementation?
I think you're referring to (unset) $var
usage. This way is related to typing the variable, such 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 not be enough?
There are times when you may need to destroy a variable and not simply have it as null, and by using $var = NULL
, $ var will continue to exist. However, to change type , yes, $var = NULL
might suffice since it has the same effect as (unset) $var
.
However, if you maintain a typing pattern, using (unset) $var
may be more convenient than $var = NULL
, because in the second case you are changing the type by assigning a new value by rewriting the variable.
An example:
#1
$var = (int)'123'
#2
$var = 123
In both cases my $ var is an int type. In the first one I forced the typing of string to integer and in the second it assigns an integer value.
Is there a case where it would be important to use (unset)
?
About this there is a lot of explanation on the DOC function, but I do not know if you mean (unset) $var
typing or the removal of the variable with unset( $var )
.
I do not know if that was exactly what you wanted to know, it was not very clear if the function or the typing was left over. If I need to, I'll try to upgrade.