为什么$ _GET和$ _POST在它们为空时返回true?

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?

  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

You should check wether they are empty or not with the empty() function or check the amount of elements with the count() function.

The arrays are always set, the question is: do they contain elements?

$_GET and $_POST both are super global variables, so these already set as Array, so you should used there empty() method instead of isset()

if(empty($_GET)){
    ...
    ...
}