Const
* The const-decorated class has a constant member property
* 1. Constants are recommended to use uppercase and cannot use $
* 2. Constants must be given a good initial value at the time of declaration
* 3. Constants are accessed in the same way as static, but are read-only
* Access class name outside class:: Constant Name
* Inside the class Access self:: constant name
<?phpheader (' Content-type:text/html;charset=utf-8 ');/* * define (' Constant name ', ' value ') * Class cannot be used define the member property of the definition * const adornment class is a constant * 1. Constants are recommended to use uppercase, and $ * 2 cannot be used. Constants must be given a good initial value at the time of declaration * 3. Constants are accessed in the same way as static, but can only be read * accessed outside the class class name:: Constant Name * accessing self within the class:: Constant name * * final Classes and methods * static properties and Methods */define (' ROOT ', str_replace (' \ \ ', '/', dirname (_ _file__)));// \ is an escape character so to represent a backslash character, two backslashes are required, which means that the backslash is escaped with an escape character echo root; class Person{ const NAME = "Jin Sha Harbor"; static function say () { echo "I Am" .self::name; } } perSon::say ();
This article is from the "Jin Sha Harbor" blog, please be sure to keep this source http://11410485.blog.51cto.com/11400485/1844677
Constants for PHP Object Const definition Classes