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