Miras (Inheritance)
class Person {
public $name;
public $age;
public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
public function introduce() {
echo "My name is {$this->name} and I am {$this->age} years old.";
}
}
class Student extends Person {
public $studentID;
public function __construct($name, $age, $studentID) {
parent::__construct($name, $age);
$this->studentID = $studentID;
}
public function studentInfo() {
echo "My name is {$this->name}, I am {$this->age} years old, and my student ID is {$this->studentID}.";
}
}
$student = new Student("John Doe", 20, "1234");
$student->introduce();
echo "<br>";
$student->studentInfo();Last updated