Detailed explanation of PHP constants and data type examples
This article mainly shares with you detailed explanations of PHP constants and data type examples, hoping to help everyone.
1. String definition methods and their differences
1. Single quotes
1.1. Single quotes cannot parse variables
1.2. Single quotes cannot parse transfer characters. They can only parse single quotes and Backslash itself
1.3, variables and variables, variables and strings, strings and strings are connected with .
2, double quotes
2.1, double quotes can parse variables, variables You can use special characters and {} to include
2.2, you can parse all transfer characters
2.3, you can also use . to connect
2.4, single quotes are more efficient than double quotes
3, heredoc and newdoc
3.1, heredoc is similar to double quotes
$str = <<
EOT;
3.2, newdoc is similar to single quotes
$str = <<<'EOT'
...
EOT;
3.3, heredoc and newdoc both handle large text
2. Extended test points
1. Data type
1.1, scalar type
A, floating point type
cannot be used for equality judgment
B, integer
C , String
D, Boolean type
FALSE seven cases: 0, 0.0, ' ', '0', false, array(), null
1.2, Composite type
A, Array
Nine built-in super-global arrays
$_SERVER variables are set by the web server or directly associated with the execution environment of the current script
$_ENV Variables submitted by the execution environment to the script
$_GET Variables submitted to the script via URL requests
$_POST Variables submitted to the script via the http post method
$_REQUEST Variables submitted to the script via get, post and cookie mechanisms, so this array is not trustworthy
$_FILES Variables submitted to the script via http, post file upload
$_COOKIE Variables submitted to the script via the http cookies method
$_SESSION Variables currently registered for the script session
$GLOBALS Contains a reference Points to a variable that is valid in the global variable scope of each current script. The key name of this array is the name of the global variable
$_SERVER Partial field description
$_SERVER['REMOTE_ADDR'];//Display the predefined variable of the client IP
$_SERVER['REMOTE_HOST'];//Current user host name;
$_SERVER['REMOTE_PORT'];//The port used by the user to connect to the server.
$_SERVER['SERVER_ADDR'];//Display the server IP address
$_SERVER['SERVER_NAME'];//Display the server name
$_SERVER['SERVER_PORT'];// Port used by the server
$_SERVER['REQUEST_TIME'];//Display request time
$_SERVER['QUERY_STRING'];//Request query parameters
$_SERVER[' HTTP_REFERER'];//Provide the source URL, that is, anti-hotlink referer
$_SERVER['PHP_SELF'];//The file name of the executing script
$_SERVER['REQUEST_METHOD'];// Request method when accessing the page
$_SERVER['REQUEST_URI'];//Request address when accessing the page
$_SERVER['SCRIPT_FILENAME'];//Absolute path name of the currently executing script
$_SERVER['PATH_INFO'];//General framework routing uses this information
B, object
1.3, special type
A, resource
B, null
2, constant
Definition method: const, define
Once a constant is defined, it cannot be modified or deleted
2.1. The difference between const and define
A. const is faster, it is a language structure, define is a function
B. const can be used for class constant definition , but define cannot
3. Magic constant
__LINE__: Returns the current line number in the file. It can also be written as __line__.
__FILE__: Returns the absolute path of the current file (including the file name).
__DIR__: Returns the absolute path of the current file (excluding the file name), 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 trait's scope or namespace).
__METHOD__: Returns the current method name (including class name).
__NAMESPACE__: Returns the name of the current file's namespace.
4. Predefined constants
Kernel predefined constants: They are constants defined in the PHP kernel. case sensitive.
PHP_VERSION: Returns the PHP version.
PHP_OS: Returns the name of the operating system where the PHP interpreter is executed.
PHP_EOL: System newline character, Windows is (\r\n), Linux is (\n), MAC is (\r).
Standard predefined constants: constants defined by PHP by default. case sensitive.
M_PI: Returns the value of pi.
5. The following predefined variables are non-global.
$php_errormsg: Previous error message, the $php_errormsg variable contains the latest error message generated by PHP. This variable is only available in the scope where the error occurred, and requires the track_errors configuration item to be turned on (it is turned off by default).
$HTTP_RAW_POST_DATA: Contains the raw data submitted by POST.
$http_response_header: HTTP response header, the $http_response_header array is similar to the get_headers() function. When using an HTTP wrapper, $http_response_header will be populated with HTTP response headers.
$argc: The number of parameters passed to the script, including the number of parameters passed to the current script when running on the command line. The file name of the script is always passed as an argument to the current script, so the minimum value of $argc is 1. This variable is only available when register_argc_argv is turned on.
$argv: Array of parameters passed to the script, containing an array of parameters passed to the current script when running on the command line. The first parameter is always the file name of the current script, so $argv[0] is the script file name. This variable is only available when register_argc_argv is turned on.
Related recommendations:
Development of code ideas for php constant usage
Several issues that need to be paid attention to when using PHP constants
The above is the detailed content of Detailed explanation of PHP constants and data type examples. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
