The content of this article is about how PHP obtains the file name (code) through the path. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Constants defined in a class.
Class constants must be defined using the const keyword
const constant name = value;
The relationship between constants and objects
Constants cannot be accessed through objects
Class name::Constant name
:: is called the range resolution operator Classes are often used inside a class to access members of the class. When using a class to access members inside the class, there is a keyword similar to $this that represents the object: self, its own meaning, represents the current class name.<?php class person(){ const HAOYUN='PHP软件开发工程师'; } //类外部获取 $person=new person(); echo $person->HAOYUN; echo HAOYUN; echo person::HAOYUN; //类内部获取
php class constant usage example analysis, php constant example analysis
php custom overall constants With class constants
The above is the detailed content of How to define class constants in PHP (with code). For more information, please follow other related articles on the PHP Chinese website!