<?php
class Person {
public $name;
public function __construct($name) {
$this->name = $name;
}
public function getData() {
return ['name' => $this->name];
}
// демонстрация позднего статического связывания
public final function getFullData() {
return static::getData();
}
}
class Student extends Person {
public $education;
public $place;
public function __construct ($name, $education, $place) {
parent::__construct($name);
$this->education = $education;
$this->place = $place;
}
public function getData() {
return array_merge(parent::getData(), [
'education' => $this->education,
'place' => $this->place
]);
}
}
$s = new Student('Alex', 'science', 'MIT');
var_dump($s->getData());
var_dump($s->getFullData());