fork download
  1. <?php
  2.  
  3. // Родительский класс - машина
  4.  
  5. class Car {
  6.  
  7. function __construct() {
  8.  
  9. $this->brand='Daewoo';
  10. $this->model='Matiz';
  11. $this->price=250;
  12. $this->info='';
  13.  
  14. }
  15.  
  16. // функция - вернуть бренд, модель и цену
  17.  
  18. public function getInfo() {
  19.  
  20. $this->info=$this->brand." ".$this->model." ".$this->price;
  21. return $this->info;
  22.  
  23. }
  24. }
  25.  
  26. // Класс Старая машина (наследник)
  27.  
  28. class oldCar extends Car {
  29.  
  30. function __construct() {
  31.  
  32. parent::__construct();
  33.  
  34. // Добавляем свойство "Возраст" (age)
  35.  
  36. $this->age=3;
  37.  
  38. }
  39.  
  40. public function getInfo() {
  41.  
  42. // Задумка была такой - получить результат
  43. //"родительской" функции getParent() и добавить к ней возраст
  44. // машины (age)
  45.  
  46. // Но при вызове ничего не выводит вообще. Где косяк?)
  47. // (не тот... а который ошибка))
  48.  
  49. $this->info=parent::getInfo()." ".$this->age;
  50. return $this->info;
  51.  
  52. }
  53.  
  54. }
  55.  
  56.  
  57. $oldcar = new oldCar();
  58. echo $oldcar->getInfo();
  59.  
  60. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Daewoo Matiz 250 3