When a newbie learns about PHP problems, he finds that the code in the book is incorrect. after he clicks it, he finds that the code is incorrect .. & Lt; meta & nbsp; http-equiv = "Content-Type" & nbsp; content = "text/html; & nbsp; charset = new ut users learn PHP problems, the code in the book is incorrect.
I found a piece of code in the book. I found it wrong after I typed it ..
Class Person
{
Private $ name;
Private $ sex;
Private $ age;
Function _ construct ($ name = "", $ sex = "male", $ age = 23)
{
$ This-> name = $ name;
$ This-> sex = $ sex;
$ This-> age = $ age;
}
Function say ()
{
Echo "My name". $ this-> name. ", Gender". $ this-> sex. ", age". $ this-> age ."
";
}
Function run ()
{
Echo $ this-> name. "walking
";
}
}
Class Student extends Person
{
Var $ school;
Function study ()
{
Echo $ this-> name. "learning". $ this-> school ."
";
}
}
Class Teacher extends Student
{
Var $ wage;
Function teaching ()
{
Echo $ this-> sex. "in". $ this-> school. "teaching, the monthly salary is". $ this-> wage ."
";
}
}
$ Teacher1 = new Teacher ("zhang san", "male", 40 );
$ Teacher1-> school = "Shenyang Institute of Technology ";
$ Teacher1-> wage = 3000;
$ Teacher1-> say ();
$ Teacher1-> run ();
$ Teacher1-> teaching ();
?>
Here, the teaching method in the Teacher class may not reach $ this-> name .. What I can get from the book is what I wrote wrong? PHP? Basic inheritance:
------ Solution --------------------
Private $ name;
Private $ sex;
Private $ age;
Private to public