This forum is now read-only. Please use our new forums at

Objects in PHP Forum

View Course » View Exercise

316 points
Submitted by
Giovanni Tempobono
about 5 years ago

My meow method does not return anything on PHP OOP I lesson 09/10


I am having problems with my meow() method on lesson 09/10 of PHP OOP I, which prints "Meow meow" on the screen but it gives me the error "Oops, try again! Your 'meow()' method does not 'return' anything."

      class Cat {
          public $isAlive = "true";
          public $numLegs = 4;
          public $name;
          public function __construct ($name) {
          public function meow() {
              echo "Meow meow";

          $cat1 = new Cat("CodeCat");


Is this some kind of bug? can you guys help me?

Thank you,

1 vote


It's probably because you're not assigning anything to name in your constructor.

public function _construct ($name) {
should be:
public function _
construct ($name) {
$this->name = $name;

1107 points
Submitted by
Nick Savov
about 5 years ago

0 votes


does it return anything? ;-)
You ought to use return and then echo. ;-)

3108 points
Submitted by
about 5 years ago


Df937fdf9871e16b784366e54a688006?s=140&d=retro xpo60rj about 5 years ago

Isn't the purpose of return to not output anything to the browser but echo is?

5154c6cf115b457ac9000021_667301409 boring12345 about 5 years ago

I don't really understand your point. Usually you use return, so your result can be accessed from everywhere. If you print it, you won't be able to access it anymore. So you can use return in the method and echo afterwards.

0 votes


I think putting echo inside the class won't print anything. You need $this->meow() for method or $this->meow for a property to access a property or method of the class. It was taught in some previous lesson. I think this is a fixed rule for accessing classes. So maybe you just need to create a return in the class and then access the method with a $this->meow();
where $this represents the object.

But what the OP has written in the meow() function seems to be legit too. Now I'm confused :D

646 points
Submitted by
about 3 years ago