Home >Backend Development >PHP Tutorial >Explanation of constants in php

Explanation of constants in php

小云云
小云云Original
2018-03-27 16:28:201259browse

An identifier of a simple value. Once a constant is defined, it cannot be changed while the script is running. This article mainly shares with you the explanation of constants in php, I hope it can help you.

System constants

  • 1) PHP_VERSION php version

  • 2) PHP_OS php running system

  • 3) PHP_INT_MAX The maximum value of the integer

Custom constant

Definition

define() function definition

define(name, value)

Note:

  • ##Do not add $ to the constant name;

  • Constant names are preferably in uppercase letters and start with a letter or underscore;

  • Constants are case-sensitive by default;

  • The value of a constant can be Scalar type, can also be an array (php7)

const Keyword definition

const name = value

Use variables

  • 1) Just use the name of the constant directly

  • 2)

    Constant(name) Get the value of the constant based on its name

Detect whether the constant

exists

defined(name)

returns

true if it exists, otherwise returns false

Return all defined constants

get_defined_constants()

Return arrays, system and custom constants

Magic variables

Between

Starting and ending with an underscore :

  • Get the current line number where the code is located

    _
    LINE _

  • Get the complete absolute path and file name of the file

    _ _ FILE_ _

  • Get Full absolute path to file

    _
    DIR _

  • Get the name of the current function

    _
    FUNCTION _

  • Get the class name of the current function

    _
    CLASS _

  • Get the method name of the current class

    _
    METHOD _

  • Get the name of the current TTRAIT

    _
    TRAIT _

  • Get the name of the current namespace

    _
    NAMESPACE _

Related recommendations:

Instance analysis of variables and constants in PHP

Detailed explanation of constants and data types in PHP

Detailed analysis of constants and variables in PHP

The above is the detailed content of Explanation of constants in php. 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