_ Unset () what's wrong with class & nbsp; Person & nbsp; {private & nbsp; $ name; private & nbsp; $ age; private & nbsp; $ sex; // 2. & nbsp; constructor // Function: & nbsp; give the object attribute _ unset (). What's wrong?
Class Person {
Private $ name;
Private $ age;
Private $ sex;
// 2. constructor // specifies the initial value of an object attribute.
Function _ construct ($ name = '', $ age = '0', $ sex = 'male '){
$ This-> name = $ name;
$ This-> age = $ age;
$ This-> sex = $ sex;
}
Private function _ set ($ proName, $ proValue ){
If ($ proName = 'age '){
If ($ proValue <0 | $ proValue> 100 ){
Echo 'invalid age ';
Return;
} Else {
$ This-> $ proName = $ proValue;
Echo $ this-> age .'
';
}
}
}
Private function _ get ($ proName ){
If ($ proName = 'age '){
Echo ($ this-> $ proName-20 ).'
';
}
}
Private function _ isset ($ proName ){
If (isset ($ this-> $ proName )){
Echo $ this-> $ proName. 'exists
';
Return;
}
Echo $ proName. 'does not exist
';
}
Private function _ unset ($ proName ){
Unset ($ this-> $ proName );
}
Function say (){
Echo 'name ........ '. $ this-> name. '| age ......... '. $ this-> age. '| sex .......... '. $ this-> sex.'
';
}
Function _ destruct (){
}
}
$ P1 = new Person ('eteng', 26, 'male ');
$ P2 = new Person ('yeben', 28, 'male ');
$ P3 = new Person ('wenjing', 40, 'female ');
$ P1-> age = 99; // automatically triggered _ set
$ P1-> age; // automatically triggered _ get
Isset ($ p1-> name); // auto-trigger _ isset
Unset ($ p1-> age); // automatically triggers _ unset
$ P1-> say ();
------ Solution --------------------
All Magic methods must be global (public)