Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2.  
  3. class Cat
  4. {
  5. protected $name;
  6. protected $color;
  7. protected $age;
  8. protected $height;
  9.  
  10. public function __construct(string $name = '', string $color = '', int $age = 0, float $height = 0)
  11. {
  12. $this->name = $name;
  13. $this->color = $color;
  14. $this->age = $age;
  15. $this->height = $height;
  16. }
  17.  
  18.  
  19. public function getName()
  20. {
  21. return $this->name;
  22.  
  23. }
  24.  
  25. public function setAge(int $a)
  26. {
  27. if ($a < $this->age) {
  28. die('Вы слишком заигрались в "Бога",ваш котик мёртв.');
  29. } else $this->age = $a;
  30. }
  31.  
  32. public function setHeight(float $h)
  33. {
  34. $this->height = $h;
  35. }
  36.  
  37. public function getAge()
  38. {
  39. return $this->age;
  40. }
  41. }
  42.  
  43. $cat0 = new Cat();
  44. var_dump($cat0);
  45. $cat = new Cat('white', 10, 10.2);
  46. var_dump($cat);
  47. $cat->setAge(11);
  48. $cat->setHeight(15.2);
  49. var_dump($cat);
  50. $cat->setAge(10);
  51. var_dump($cat);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement