Class constants: A class that holds unchanged data for the duration of a run.
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 = ' woman ';}
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: Members that can be defined in a class: constants, static properties, non-static properties, static methods, non-static methods.
Note: $this represents the current object and always represents the object of the class where $this is located?
No, because the value of $this does not depend on the class in which the $this resides, but on the execution object (execution Environment) when the $this method is called.
The execution environment of the method in which the current method is executed in the context of the object, within the method
$this represents which object.