fork download
  1. <?php
  2.  
  3.  
  4. class Worker {
  5. public $name;
  6. public $level;
  7. public $chief; // Принимает значения True or False
  8.  
  9.  
  10. function __construct($workers_name, $workers_level, $is_chief) {
  11. $this->name = $workers_name;
  12. $this->level = $workers_level;
  13. $this->chief = $is_chief;
  14. }
  15. }
  16. class Manager extends Worker {
  17.  
  18. protected $paid = 500;
  19. protected $pages = 200;
  20. protected $coffe = 20;
  21.  
  22. public function drinkCoffe() {
  23. if ($this->chief == True) {
  24. return ($this->coffe * 2);
  25. } else {
  26. return $this->coffe;
  27. }
  28. }
  29. }
  30. $Peter = new Manager('P. Stivenson', 2, True);
  31. echo $Peter->drinkCoffe();
  32.  
  33. /* Стоит создать для каждого типа работника - отдельный подкласс Worker */
  34. ?>
  35.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
40