Search code examples
phparrayspostgetisset

Why on earth do $_GET and $_POST return true when they're empty?


http://codepad.org/3duGkQZi

I understand that if $var = array(), $var will return true because even though the array is empty, it's still a set variable.

But $_GET and $_POSTare not just arrays, they are arrays generated by PHP.

Why does PHP even set these variables if there's nothing to put in them? Is there something logical behind this that I'm missing?


Solution

    1. Superglobals are built-in variables that are always available in all scopes
    2. $_GET is a superglobal variable

    therefore, $_GET is always available. This is the decision of the language developers.

    http://www.php.net/manual/en/language.variables.superglobals.php