What are PHP superglobals?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for PHP development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
Superglobals are built-in PHP variables that are always accessible regardless of scope — they can be used in any function, class, or file without needing to declare them global. PHP has nine superglobals: $GLOBALS (all global variables), $_SERVER (server/execution environment info), $_GET (URL query string parameters), $_POST (HTTP POST form data), $_FILES (file upload data), $_COOKIE (HTTP cookies), $_SESSION (session variables), $_REQUEST (combination of GET, POST, and COOKIE), and $_ENV (environment variables). Always sanitize and validate data from superglobals before using it — they contain user-supplied input and are common vectors for injection attacks.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong PHP candidates.
Previous
What is the difference between == and === in PHP?
Next
What is the difference between GET and POST methods in PHP?