PHP Object-Class constants
Class constants: In a class, save unchanged data in the running cycle.
Defined:
const keyword
const constant NAME = constant value
Example:
Class Student
{
Public $stu _id;
Public $stu _name;
Public $stu _gender;
Const Gender_male = ' Male ';
Const Gender_female = ' female ';
}
Class constants are not restricted by access-qualified modifiers
Access:
Class:: Constant Name
Example:
Class Student
{
Public $stu _id;
Public $stu _name;
Public $stu _gender;
Const Gender_male = ' Male ';
Const Gender_female = ' female ';
Public function __construct ($id, $name, $gender = ')
{
$this->stu_id= $id;
$this->stu_name= $name;
$this->gender= ($gender = = ") Self::gender_male: $gender;
}
}
Summary: The members that can be defined in a class, altogether: constants, static properties, Non-static properties, static methods, and Non-static methods.
Note: $this represents the current object, always representing the object of the $this's class?
No, because the value of the $this does not depend on the class in which the $this resides, but on the execution object (execution Environment) when the method is invoked $this.
The execution environment of the method, the current method is executed in the context of which object, the
$this represents which object.