Superglobals are built-in arrays available in every scope: $_GET, $_POST, $_SERVER, $_SESSION, $_COOKIE, $_FILES, $_ENV. They mirror HTTP input and server metadata.
Common superglobals
$_GET— query string parameters (?page=2)$_POST— form body fields (application/x-www-form-urlencoded or multipart)$_SERVER— request method, URI, headers (asHTTP_*keys)$_SESSION— server-side session bag aftersession_start()
Playground simulation
The runner may not populate real superglobals. Treat sample arrays as stand-ins—the access pattern is identical:
$_GET = ['id' => '5']; // simulated
$id = (int) ($_GET['id'] ?? 0);
Security mindset
Never trust superglobal values. Validate, cast, and use prepared statements for database work. Escape on output.
Important interview questions and answers
- Q: GET vs POST superglobals?
A:$_GETfrom query string;$_POSTfrom request body—method choice affects caching, bookmarks, and size limits. - Q: Why are they called superglobals?
A: They are always available withoutglobal
Self-check
- Which superglobal holds
REQUEST_METHOD? - Why cast
$_GET['id']to int?
Tip: Treat every superglobal value as untrusted—validate, cast, and never concatenate raw input into SQL.
Interview prep
- Which superglobal for form POST fields?
$_POSTholds body fields from POST requests; validate withfilter_inputor explicit checks before use.