New students learn about PHP problems, found that the code is wrong

Source: Internet
Author: User
New students learn PHP problem, found that the code is wrong
Found a piece of code in the book, knocked down and found the wrong.


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. " Is walking
";
}
}

Class Student extends Person
{
var $school;
Function study ()
{
echo $this->name. " Being ". $this->school." Learn
";
}
}
Class Teacher extends Student
{
var $wage;
function Teaching ()
{
echo $this->sex. " Being ". $this->school." Teaching, the salary per month is ". $this->wage."
";
}
}
$teacher 1=new Teacher ("Zhang San", "male", 40);
$teacher 1->school= "Shenyang Institute of Technology";
$teacher 1->wage=3000;

$teacher 1->say ();
$teacher 1->run ();
$teacher 1->teaching ();
?>

Here teacher the teaching method in the class or do not go to $this->name. The book is written can be obtained, where I wrote the wrong? PHP? Basics Inheritance

Share to:


------Solution--------------------
Private $name;
Private $sex;
Private $age;
Private change 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.