The documentation for NULL says that if I called unset()
on a variable, the variable will become NULL:
A variable is considered to be null if:
it has been assigned the constant NULL.
it has not been set to any value yet.
it has been unset().
However, this tutorial says the following will happen when calling unset()
on a variable:
PHP looks in the symbol table to find the zval corresponding to this variable, decrements the refcount, and removes the variable from the symbol table. Because the refcount is now zero, the garbage collector knows that there is no way of accessing this zval, and can free the memory it occupies.
Now I tried the following code:
<?php
$x = 12345;
unset($x);
echo gettype($x);
?>
The output I got is strange, I got an error that says that the variable is undefined (which conforms with the second quote I have posted), but I also got the type of the variable which is NULL (which conforms with the first quote I have posted):
Why am I getting this strange output?