Home > Backend Development > PHP Tutorial > Introduction to constants and system constants for getting started with PHP_PHP tutorial

Introduction to constants and system constants for getting started with PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:29:52
Original
838 people have browsed it

PHP constants are case-sensitive by default. Traditionally constant identifiers are always uppercase.

PHP constant names follow the same naming rules as any other PHP tag. Legal constant names begin with a letter or an underscore, followed by any letters, numbers, or underscores. The regular expression is expressed as follows: [a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*.

Copy code The code is as follows:

// Legal constant name
define("FOO", "something");
define("FOO2", "something else");
define("FOO_BAR", "something more" ");

//Illegal constant name
define("2FOO", "something");

// The following definition is legal, but should be avoided: (custom constants do not start with __)
// Maybe one day in the future PHP will define a magic constant of __FOO__
// This will conflict with your code
define("__FOO__", "something");

?>

Summary:
1. Custom constants
* Must be defined using the function define()
* After definition, its value cannot be changed
* When used, use the constant name directly, not like a variable Just add $s in front

2 System constants:
FILE: PHP program file name
LINE: PHP program file line number
PHP_VERSION: The version number of the current parser
PHP_OS: The name of the operating system that executes the current PHP version
__FILE__ The name of the script file currently being processed.
__LINE__ The current line number of the script file currently being processed, the same as before.

TRUE means true.
FALSE represents a false value (false).

E_ERROR This constant points to the most recent error.
E_WARNING This quantity refers to the nearest warning.
E_PARSE This constant is a potential problem in parsing syntax.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/769239.htmlTechArticlePHP constants are case-sensitive by default. Traditionally constant identifiers are always uppercase. PHP constant names follow the same naming rules as any other PHP tag. Legal constant names start with letters or underscores...
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