class Person {
protected $m_name;
protected $m_age;
function __construct($name, $age) {
$this->m_name = $name;
$this->m_age = $age;
}
public function SayHello() {
echo $this->m_name . ", age " . $this->m_age . " says hello!";
}
}
class Student extends Person {
protected $m_grade;
function __contruct($name, $age, $grade) {
parent::__construct($name, $age);
$this->m_grade = $grade;
}
public function SayHello() {
echo $this->m_name . ", age " . $this->m_age . " says hello! (Grade: " . $this->m_grade . ").";
}
}
$Bob = new Person('Bob', 29, 5);
$Bob->SayHello();
echo '<br />';
$Bill = new Student('Bill', 21, 5);
$Bill->SayHello();
Output:
Bob, age 29 says hello! Bill, age 21 says hello! (Grade: ).Variable $m_grade never gets a value. I saw this in a tutorial here but I can't see what I'm doing wrong. How can I accomplish this?


Sign In
Create Account

Back to top









