Home  >  Article  >  Backend Development  >  Summary of PHP constant definitions and usage examples

Summary of PHP constant definitions and usage examples

伊谢尔伦
伊谢尔伦Original
2017-06-13 10:45:091596browse

What are class constants? In PHP, we can understand that a quantity whose value does not change is called a constant. So, what is a class constant? In fact, class constants are also easy to understand. We can call the value that always remains unchanged in the class a constant, and this constant can be called a class constant. Be sure to remember that you do not need to use the "$" symbol when defining and using constants. Class constants belong to the class itself, not to object instances, and cannot be accessed through object instances * Cannot be modified with public, protected, private, static * Subclasses can override constants in the parent class, and can call the parent class through (parent::) Constants in * Since PHP5.3.0, you can use a variable to dynamically call a class. But the value of this variable cannot be a keyword (such as self, parent or static). Definition of class constants Class constants are defined using the const keyword: const constant name = constant value Example defining and using a class constant

1. php class constant definition and example details

Summary of PHP constant definitions and usage examples

Introduction: What is a class constant? In php, we can understand that a variable with a constant value is called a constant. Yes, what is a class constant? In fact, a class constant is also easy to understand. We can always refer to it as a constant in a class. The value that remains unchanged is called a constant, and this constant can be called a class constant. Be sure to remember that you do not need to use the "$" symbol when defining and using constants. 2. Detailed explanation of JavaScript constant definition

Summary of PHP constant definitions and usage examplesIntroduction: I believe that when students see this title I'm confused, what? Can JS be defined as a constant? To be precise, there are no constants in JS (there seems to be a keyword for constant definition in ES6), but if we dig deeper, we can find that there are many in JS. Little-known properties, if you make good use of these properties, you will find a different JS world. First of all, in JS, the properties of objects actually contain their own implicit properties, such as the following objects: var obj = {}; obj. .a = 1; obj.b = 2; Here we define an object obj and define this pair..

3. php constant definition problem

Introduction: {code...} Can the constant FRUIT here be defined as ['apple', 'orage'] (this is an array, right), FRUIT Shouldn't it be a number or a string? Please answer!

#4. PHP self-study no00013 determine whether the constant value has been defined

Introduction::PHP self-study no00013 constant definition value to determine whether it has been defined:

5. Comparison between APC constant definition and PHP define_ PHP tutorial

##Introduction: Comparison of APC constant definition and PHP define. Recently, when doing the preliminary code architecture of the cloud platform, I encountered a constant definition. The problem of speed comparison is to make a comparison. The APC extension of PHP has the following description in the PHP manual: hSummary of PHP constant definitions and usage examples

6.

php defineThe difference between constant definition and variable_ PHP tutorial

##Introduction: The difference between PHP define constant definition and variable. Constants must be defined before use, otherwise the program execution will go wrong. Use the define() function in the PHP tutorial. To define constants. 1. Syntax format: define (constant name, constant value); For example: ##7. php basics-constants-variable-related basic functions_PHP Tutorial

##Introduction: PHP basics-constants-variable-related basic functions. PHP basics-constants-variable-related basic functions comment statements //Single line #Single line/*Multiple lines Comments*/ /*** Document comments **/ Constant definition custom constant constant name case-sensitive system

8. Learn the constants of PHP on the front end, learn the constants of PHP_PHP tutorial

Introduction: learn the constants of PHP on the front end, learn the constants of PHP constant. Learn PHP constants on the front end, learn PHP constant directory [1] Constant definition [2] Custom constants [3] System constants [4] Constant values ​​[5] defined() Constant definition Constants are similar to variables, but once the constant is defined

9. The difference between const and define in PHP constant definition

Introduction: const and define in PHP constant definition The difference is that in constant definition in PHP, two methods, const and define, can be used to define constants. So what is the difference between them? The following is an analysis of the difference between const and define in PHP constant definition from 8 aspects: 1. Const is used to define class member constants. Once defined, it cannot be modified. define cannot be used for the definition of class member constants, but can be used for global constants. 2. Const can be used in classes, but define cannot. 3. const cannot define constants in conditional statements

10. php variable constant definition method

Introduction: php How to define variables and constants Definition instructions for some common static constants under PHP. 1. Define constants define("CONSTANT", "Hello world."); Constants can only contain scalar data (boolean, integer, float and string). When calling a constant, you only need to simply use the name to get the value of the constant, without adding the "$" symbol, such as: echo CONSTANT; Note: Constants and (global) variables are in different namespaces.

[Related Q&A recommendations]:

php constant definition problem

After constant definition Can it still be modified?

php - Why does laravel use env extensively instead of the commonly used constant definition method?

How to use const to define another constant in PHP

The above is the detailed content of Summary of PHP constant definitions and usage examples. 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