Home > Backend Development > PHP Tutorial > php predefined variables

php predefined variables

伊谢尔伦
Release: 2016-11-24 13:47:50
Original
1314 people have browsed it

PHP provides a large number of predefined variables. Detailed documentation is not available as many variables depend on the version and settings of the running server, among other factors. Some predefined variables do not take effect when PHP is run from the command line.

Warning

In PHP 4.2.0 and subsequent versions, the default value of the PHP directive register_globals is off. This is a major change to PHP. Setting register_globals to off affects the global availability of the predefined set of variables. For example, to get the value of DOCUMENT_ROOT, you would have to use $_SERVER['DOCUMENT_ROOT'] instead of $DOCUMENT_ROOT. Another example, use $_GET['id'] instead of $id from the URL http://www.example.com/test Get the id value in .php?id=3, or use $_ENV['HOME'] instead of $HOME to get the value of the environment variable HOME.

It’s best to use PHP predefined variables, such as superglobal arrays.

Starting with PHP 4.1.0, PHP provides an additional set of predetermined array variables that contain data from the web server (if available), the runtime environment, and user input. These arrays are very special in that they automatically take effect globally, i.e. automatically in any scope. Therefore they are often called autoglobals or superglobals. (There is no mechanism for user-defined superglobal variables in PHP.) Superglobal variables are listed below; but for their contents and further discussion of PHP's predefined variables and their nature, see Predefined Variables. Furthermore, you will also notice that the old predefined arrays ($HTTP_*_VARS) are still present. As of PHP 5.0.0, long-type PHP predefined variable arrays can be disabled with the register_long_arrays setting option.

Note: Mutable variables

Super global variables cannot be used as mutable variables in functions or class methods.

Note:

Although superglobal variables and HTTP_*_VARS exist at the same time, they are not the same variable, so changing the value of one will not affect the other.

If some variables in variables_order are not set, their corresponding PHP predefined arrays will also be empty.


Related labels:
php
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