Magic constants, pre-defined constants, and predefined variables in PHP

Source: Internet
Author: User
Tags http cookie http file upload http post value of pi
1. Magic Constants

There are eight magic constants in PHP, and their values change as they change position in the code. These special constants are case insensitive.

    • Line: Returns the current row number in the file. Can also be written in line.

    • File: Returns the absolute path (including the file name) of the current file.

    • DIR: Returns the absolute path (without the file name) of the current file, equivalent to DirName (file).

    • Function: Returns the name of the current function (or method).

    • Class: Returns the current class name (including the scope or namespace of the class).

    • TRAIT: Returns the current TRAIT name (including the scope or namespace of the TRAIT).

    • Method: Returns the current methods name (including the class name).

    • NAMESPACE: Returns the name of the namespace for the current file.

2. Pre-defined constants

Kernel predefined constants: Constants that are defined in the kernel of PHP. is case sensitive.

Php_version: Returns the version of PHP.

Php_os: Returns the name of the operating system executing the PHP interpreter.

Php_eol: System line break, Windows is (\ r \ n), Linux is (\ n), Mac is (\ r).


Standard predefined constants: Constants defined by PHP by default. is case sensitive.

M_PI: Returns the value of Pi Pi.

3. Pre-defined variables

Many of the predefined variables in PHP are "hyper-global", which means they are available in all scopes of a script. You can access these functions or methods without having to perform the global $variable.

A hyper-global variable is a built-in variable that is always available in all scopes.

    • $GLOBALS: global variable, which is a combined array containing all global variables, and the name of the global variable is the key of the combined array.

    • $_get:http the GET variable, passed to the array of variables of the current script through the URL parameter.

    • $_post:http post variable, an array of variables passed to the current script via the HTTP post method.

    • $_cookie:http cookie variable, an array of variables passed to the current script by means of an HTTP cookie.

    • $_session:session variable, an array of SESSION variables available for the current script.

    • The $_request:http REQUEST variable, which by default contains an array of $_get,$_post and $_cookie.

    • $_files:http file upload variable, an array of items uploaded to the current script via the HTTP POST method.

    • $_server: A server information variable that contains an array of information such as header information (header), path, and script location (scripts locations). The items in this array are created by the WEB server.

    • $_env: An array of environment variables that are passed to the variables of the current script in an environment way.

The above predefined variables are super global variables.

The following predefined variables are non-global.

$php _errormsg: The previous error message, $php _errormsg variable contains the most recent error message generated by PHP. This variable is only available within the scope of the error, and requires that the Track_errors configuration item be turned on (it is off by default).


$HTTP _raw_post_data: Contains the original data for the POST submission.

$http the _response_header:http response header, $http _response_header array is similar to the get_headers () function. When using the HTTP wrapper, the $http _response_header will be populated with HTTP response header information.

$ARGC: The number of arguments passed to the script, including the number of arguments passed to the current script when running under the command line. The file name of the script is always passed as a parameter to the current script, so the minimum value for the $ARGC is 1, which is only available when REGISTER_ARGC_ARGV is open.

$ARGV: An array of arguments passed to the script that contains the arguments passed to the current script when run on the command line. The first parameter is always the file name of the current script, so $argv [0] is the script file name, which is only available when REGISTER_ARGC_ARGV is open.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.