PHP Predefined Variables
For now, we’ll quickly go over PHP predefined variables, but we will delve deeper into them in future posts that will also be part of PHP 101.
Superglobals — These are internal variables that are always available, meaning it doesn’t matter whether you’re in a local or global scope.
Superglobal variables:
$GLOBALS
— Refers to all variables available in the global scope.
It is an associative array containing references to all the variables defined in the global scope of the script. The variable names are the keys of the array. See variable scope.
$_SERVER
— Contains server and execution environment information.
$_GET
— An array that contains HTTP GET variables.
$_POST
— An array that contains HTTP POST variables.
$_FILES
— HTTP File Upload variables.
$_REQUEST
— Contains HTTP request variables. Contains the combined contents of $_GET
, $_POST
, and $_COOKIE
arrays
$_SESSION
— An array that contains session variables.
$_ENV
— Contains environment variables.
$_COOKIE
— HTTP Cookies, contains cookies if used.
Other PHP predefined variables:
$php_errormsg
— Contains the previous error message.
$HTTP_RAW_POST_DATA
— Contains the raw POST data.
HTTP_RAW_POST_DATA
-Is deprecated since versions 5.6 and 7, so avoid using it if possible.
$http_response_header
— When using the HTTP wrapper (http://
), $http_response_header
is populated with the HTTP response headers. It will be created in the local scope.
$argc
— Contains the number of arguments passed to the script.
$argv
— An array with the arguments passed to the script, typically a PHP file.
- Anterior: Generadores
- Siguiente: Excepciones predefinidas