Introduction to Constants and System Constants for PHP

  • 2021-06-28 11:32:50
  • OfStack

The PHP constant defaults to case sensitive.Traditionally, constant identifiers are always capitalized.

The PHP constant name follows the same naming rules as any other PHP tag.Legal constant names start with a letter or an underscore followed by any letter, number, or underscore.Expressed in a regular expression: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.

//  Legal Constant Name 
define("FOO",     "something");
define("FOO2",    "something else");
define("FOO_BAR", "something more");
//  Illegal constant name 
define("2FOO",    "something");
//  The following definitions are legal but should be avoided: ( Custom constants should not be __ Start )
//  Maybe in the future 1 day PHP Will define 1 individual __FOO__ Magic Constant of 
//  This will conflict with your code 
define("__FOO__", "something");

1. Custom Constants
*Must be defined with function define()
* Value cannot be changed after definition
*Use constants directly instead of $s in front like variable 1

2 System Constants:
FILE: php program file name
LINE: Lines of PHP program files
PHP_VERSION: Version number of current parser
PHP_OS: The name of the operating system that is executing the current version of PHP
_uFILE_uThe name of the script file currently being processed.
_uLINE_uCurrent number of lines of script file currently being processed, same as before.

TRUE represents the true value (true).
FALSE represents a pseudo value (false).

E_The ERROR constant refers to the most recent error.
E_WARNING refers to the most recent warning.
E_PARSE is a potential problem with parsing grammar.

Related articles: