New users learn PHP problems and find the code on the book is incorrect

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.