New users learn PHP problems and find the code in the book is incorrect-php Tutorial

Source: Internet
Author: User
Tags php basics
New users learn PHP problems and find that the code in the book does not inherit the PHP Basics.

I found a piece of code in the book. I found it wrong after I typed it ..
 
 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 Progress ". $ this-> school. "Teaching, the monthly salary is ". $ this-> wage."
";}}$ Teacher1 = new Teacher (" Michael Zhang "," 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?


Reply to discussion (solution)

Yes $ this-> sex cannot get data.

Amount .... I am so careless. the above variable defines the private attribute, and of course it cannot be obtained...

Birds of the same dish fly over .........

You are not wrong. you are not wrong in the book!
It's just that the error check levels are different.

Error_reporting = E_ALL ^ E_NOTICE
It is consistent.

You are not wrong. you are not wrong in the book!
It's just that the error check levels are different.

Error_reporting = E_ALL ^ E_NOTICE
It means that the moderator is strong, refreshing, and hard-working!

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.