PHP __get () __set () __construct ()
function __construct ($name, $sex, $age, $school)
??? ??? {
??? ??? ??? $this->name= $name;
??? ??? ??? $this->sex= $sex;
??? ??? ??? $this->age= $age;
??? ??? ??? $this->school= $school;
}
?
?
?
function __get ($property _name)
?? {?
??? echo "Automatically calls this __get () method when it directly acquires the value of a private property.
";
???? if (Isset ($this-$property _name)) {
???? Return ($this, $property _name);
??? }else {
???? return (NULL);
???}
??}
?? The __set () method is used to set the private property
?? function __set ($property _name, $value)
?? {
?? "echo" Automatically calls this __set () method to assign a value to a private property when setting the value of a private property directly
";
??? $this $property _name = $value;
??} ?
?
?
function Setage ($age)? provide an external method for setting the age of a public
??? {
??? ??? if ($age <0 | | $age >130)// when assigning a value to a property, in order to avoid an illegal value set to the property
??? ??? ??? Return
??? ??? $this->age= $age;
}
function Getage () ??? to provide an external public access to the age method
{
??? Return ($this->age);
}
?