I. Class constants: Values that remain constant in a class are defined as constants
The constants of a class cannot use the access restriction modifier, which is public, inheritable, and can be overridden by a quilt class, and constants that access a class must use a double colon::, you can access it using the class name or an instance of the class, because it is a constant, so the name cannot be used to represent the variable's symbol $.
You can define a value that is always the same in a class as a constant. You do not need to use the $ symbol when defining and using constants.
The value of a constant must be a fixed value, not a variable, a class property, a result of a mathematical operation, or a function call.
You can also define constants in the interface (interface). See the interface section in the documentation for more examples.
From PHP 5.3.0, a variable can be used to dynamically invoke a class. However, the value of the variable cannot be a keyword (such as self,parent or static).
Syntax: const constant= ' constant ';
Class myclass{Const constant = ' constant ';//type internal call public function test () { echo self::constant. ' <br> '; }}myclass::test ();//class external access echo myclass::constant. ' <br> '; Method One $obj = new Myclass (); Method two echo $obj:: Constant. ' <br> ';
Two. Static property: Is a variable, can be constant syntax access, that is::, can not be instantiated also can access
Syntax: public static $my _static = ' similar constants ';
Class myclass{public static $static _val = ' static property ';//class internal access public function test () { return self:: $static _val. ' <BR&G t; '; }}//class external access//echo myclass::test (); Echo Myclass:: $static _val; Method One $obj = new Myclass (); Method two echo $obj:: $static _val;echo $obj->test ();
Three. Non-static properties: A normal variable that can be accessed after instantiation, with the symbol
Syntax: public $my _val = ' normal variable '
Class myclass{public $normal _val = ' non-static property ';//class internal access public function test () { return $this->normal_val;}} Class external Access $obj = new Myclass (); echo $obj->normal_val;echo $obj->test ();
PHP gets methods for constants, attributes, and method lists in a class
$r = new Reflectionclass ($this); Zend_debug::d UMP ($r->getconstants (), "Constants"); Zend_debug::d UMP ($r->getproperties (), "Properties"); Zend_debug::d UMP ($r->getmethods (), "Methods");