Home > Backend Development > PHP Tutorial > The use of const keyword in PHP programs

The use of const keyword in PHP programs

WBOY
Release: 2016-07-29 09:12:01
Original
1278 people have browsed it

Usage environment:

You can use define to define constants in PHP, but you cannot use define in classes. In classes, the values ​​of some attributes do not want to be modified. In this case, we need to use const to define them. constant.

Usage:

1. Member attributes modified with const are constants. In a class, const can only modify member properties.

2. It is recommended to use uppercase letters for constants. You cannot use $

3. The initial value of the constant must be given when it is declared

4. The access method of constants is the same as static, using ::, but Can only read

1. Use it outside the class class name::constant name

2. Use it inside the class self::constant name

The above introduces the use of the const keyword in PHP programs, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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