Home > Backend Development > PHP Tutorial > What is the super global variable in php

What is the super global variable in php

一个新手
Release: 2023-03-16 13:42:01
Original
3840 people have browsed it

In PHP, superglobal variables were introduced in "PHP4.1" and are built-in variables that are always available in all scopes. Superglobal variables can be accessed from any function, class, or any file without performing any special task like declaring any global variables; they are mainly used to store and retrieve information from one page to another in the application.

What is the super global variable in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

What is Superglobals? variable?

Superglobal variables are built-in variables introduced in PHP4.1 that are always available in all scopes. Superglobal variables can be accessed within a function or method without using the global keyword.

They can use super global variables to access information at any time and anywhere in the script. That is, regardless of the scope, information about the request or its context can be easily obtained.

Super global variables can be accessed from any function, class or any file without performing any special task like declaring any global variable etc. They are mainly used to store and retrieve information from one page to another in the application.

Extension:

There are many superglobal variables in PHP, which means that they are available in the entire scope of a script. They can be accessed within a function or method without executing global $variable;.

These superglobal variables are:

  • $GLOBALS: refers to all variables available in the global scope. A global combined array containing all variables. The name of the variable is the key of the array.

  • $_SERVER: An array containing information such as header, path, and script location. The items in this array are created by the web server. There is no guarantee that every server will offer all items; servers may ignore some, or serve items not listed here.

  • $_GET: HTTP GET variables, an array of variables passed to the current script through URL parameters.

  • $_POST: HTTP POST variable. When the Content-Type of the HTTP POST request is application/x-www-form-urlencoded or multipart/form-data, the variable will be associated with Pass the current script in array form.

  • $_FILES: HTTP file upload variable, an array of items uploaded to the current script through HTTP POST.

  • $_COOKIE: HTTP Cookies, an array of variables passed to the current script through HTTP Cookies.

  • #$_SESSION: Session variable, an array of SESSION variables available in the current script.

  • $_REQUEST: HTTP Request variable, which by default contains arrays of $_GET, $_POST and $_COOKIE. $_FILES information has been removed from $_REQUEST since PHP 4.1.

  • #$_ENV: Environment variable, an array of variables passed to the current script through the environment. These variables are imported from the PHP parser's runtime environment into PHP's global namespace. Many are provided by shells that support PHP running, and different systems are likely to run different kinds of shells, so a definitive list is impossible.

For more related knowledge, please visit PHP Chinese website! !

The above is the detailed content of What is the super global variable in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template