Forum Moderators: coopster
This should clarify. Dump this in isset.php then call it directly, like example.com/isset.php.
<?php
if (isset($_GET['foo'])) { echo "Foo has been set <br>\n"; }
else { echo "no foo <br>\n"; }
echo "The variable type of foo is " . gettype($_GET['foo']) . "<br>\n";
echo "Now let's unset it:<br>\n";
unset($_GET['foo']);
if (isset($_GET['foo'])) { echo "Foo has been set <br>\n"; }
else { echo "no foo <br>\n"; }
?>
The gettype() will kick an error, but it tell us what you need to know - you should get
no foo
Notice: Undefined index: foo in /path/to/isset.php on line 4
The input value of foo is NULL
Now let's unset it:
no foo
Now call it with a query string, example.com/isset.php?foo=1
Foo has been set
The variable type of foo is string
Now let's unset it:
no foo
But wait! Try
example.com/isset.php?foo
Just like that without an equal sign after foo to set a value, not even ''.
Guess what you get? You might expect null, but no. It's an empty string.
Foo has been set
The variable type of foo is string
Now let's unset it:
no foo