Reputation: 682
Is it possible to pass Null value via Post / Get?
By null, I mean something that will return true on isset()
but false on empty()
.
Reason is, I want to know if I need an extra check on $_GET
where I'm checking the following:
if (isset() && !empty()) {
// do stuff
} elseif (isset() && empty()) { // In other words, omit this one.
// do other stuff
} else {
//foo bar
}
Thanks,
Upvotes: 1
Views: 2630
Reputation: 3874
If a GET variable is not present (i.e. script.php), you will get:
isset($_GET['var']) = false
empty($_GET['var']) = true
If it is present but has no value (i.e. script.php?test=), you will get:
isset($_GET['var']) = true
empty($_GET['var']) = true
Thus testing that isset($_GET['var']) && !empty($_GET['var'])
is enough to guarantee that your GET variable exists and has a proper value.
Upvotes: 5