fizzy drink
fizzy drink

Reputation: 682

is it possible to pass Null value via Post / Get? (PHP)

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

Answers (1)

christophetd
christophetd

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

Related Questions