PHP is a widely used programming language. Constants are important elements that are often used in programs. They do not change their values. They are global and can be called at any time. In PHP programming, there are many commonly used constants. In this article, I will explain in detail the common constants in PHP programming.
-
FILE
FILE Constants are used to obtain the full path and file name of the current file, which can easily locate problems in the code.
Example:
echo __FILE__;
Output: C:
mpphtdocs est.php
- ##LINE
LINE Constants are used To get the line number of the current code. Example:
echo __LINE__;
Output: 3
- DIR
DIR Constant is used to get the directory path where the current file is located . Example:
echo __DIR__;
Output: C:
mpphtdocs
PHP_VERSION- PHP_VERSION constant is used to get the current PHP version number.
Example:
echo PHP_VERSION;
Output: 7.4.12
PHP_OS- PHP_OS constant is used to get the name of the current operating system.
Example:
echo PHP_OS;
Output: WINNT
PHP_EOL- The PHP_EOL constant is used to obtain the system-specific end-of-line glyph and can be used for cross-platform compatible output.
Example:
echo "Hello" . PHP_EOL . "world!";
Output:
Hello
world!
TRUE/FALSE- TRUE and FALSE constants Represents true and false in Boolean values.
Example:
$bool = TRUE;
var_dump($bool);
Output: bool(true)
NULL- NULL constant is used to indicate that a variable has no value .
Example:
$var = NULL;
var_dump($var);
Output: NULL
PHP_INT_MAX- PHP_INT_MAX constant is used to obtain the values that can be expressed in the current PHP environment Maximum integer value.
Example:
echo PHP_INT_MAX;
Output: 9223372036854775807 (64-bit system)
PHP_INT_SIZE- The PHP_INT_SIZE constant is used to obtain the number of bytes of the integer in the current PHP environment.
Example:
echo PHP_INT_SIZE;
Output: 8
The above are common constants in PHP programming. They can be conveniently used for determination and assignment of variables in the program, and It is global and convenient for code calling. When developers use these constants, they need to pay attention to their functions and usage. Proper use of them can improve development efficiency and program readability.
The above is the detailed content of What are the common constants in PHP programming?. For more information, please follow other related articles on the PHP Chinese website!
Statement: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