The catch of this question and how "perfect" solved this?

In the job ognor to write a Cat class that inherits from the Animal class. The Animal class has a method getName (name can be passed to the constructor).

Class Cat has a method meow (returns the string "Cat {catname} is sayig meow".

Example usage:
$cat = new Cat ('garfield');
$cat->getName () === 'garfield' // true;
$cat->meow () === 'garfield the Cat is saying meow' // true;


Here is my realizeze... What's wrong with her? Why the validator is "wrapped" her?

<?php
abstract class Animal {
 public $name;
 public function __construct($cat_name) {
 $this--->name = $cat_name;
}
}

class Cat extends Animal {
 public function meow() {
 echo "<br>Cat {$this->name} is saying meow ";
}
 public function getName() {
 return $this->name;
}
}

$cat = new Cat('garfield');
echo $cat->getName();
$cat->meow();
June 14th 19 at 18:16
4 answers
June 14th 19 at 18:18
Solution
Not a coincidence with the assignment in paragraph
The Animal class has a method getName

Also, the method meow() must return a string, not output it. Well, <br> should not be there
and a method meow() must return a string and not display it, according to
$cat->meow () === 'garfield the Cat is saying meow' // true;
- Mabelle.Gerhold86 commented on June 14th 19 at 18:21
agree, added response - Dahlia.Swi commented on June 14th 19 at 18:24
June 14th 19 at 18:20
Solution
There is a getter:
public function getName() {
 return $this->name;
 }

I would do $name => protected instead of public.
June 14th 19 at 18:22
Solution
Because the "Animal Class has a method getName"
June 14th 19 at 18:24
No hiccups there.
Also did not see, but somehow too simple to be the truth. Maybe paranoia already - Mabelle.Gerhold86 commented on June 14th 19 at 18:27
The Animal class has a method getName

You have this method in the cat class - Dahlia.Swi commented on June 14th 19 at 18:30

Find more questions by tags PHP