Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Cat
- {
- protected $name;
- protected $color;
- protected $age;
- protected $height;
- public function __construct(string $name = '', string $color = '', int $age = 0, float $height = 0)
- {
- $this->name = $name;
- $this->color = $color;
- $this->age = $age;
- $this->height = $height;
- }
- public function getName()
- {
- return $this->name;
- }
- public function setAge(int $a)
- {
- if ($a < $this->age) {
- die('Вы слишком заигрались в "Бога",ваш котик мёртв.');
- } else $this->age = $a;
- }
- public function setHeight(float $h)
- {
- $this->height = $h;
- }
- public function getAge()
- {
- return $this->age;
- }
- }
- $cat0 = new Cat();
- var_dump($cat0);
- $cat = new Cat('white', 10, 10.2);
- var_dump($cat);
- $cat->setAge(11);
- $cat->setHeight(15.2);
- var_dump($cat);
- $cat->setAge(10);
- var_dump($cat);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement