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

Objects in PHP Forum

View Course » View Exercise

526 points
Cc295c27f59e7a8ecc853264009c03c2?s=140&d=retro
Submitted by
melaniesazegar
over 2 years ago

9/10 Parse error: syntax error, unexpected '(', expecting T_STRING on line 17

I'm able to pass with the following code but I don't see why the opening parentheses is unexpected and what string the code was expecting instead?

<?php
        class Cat {
            public $isAlive = true;
            public $numLegs = 4;
            public $name;
            public function __construct ($name) {
                $this->name = $name;
                }
            function ($meow) { // THIS IS LINE 17
                return "" . $this->name . "Meow meow";
                }
            }

        $cat1 = new Cat("CodeCat");
        echo $cat1->meow();
    ?>

-2 votes

permalink

Nvm, I got the answer. Instead of:

function ($meow)

I needed to have:

 public function meow () {

FWIW I also cleaned up the code and changed the next line from this:

return "" . $this->name . "Meow meow";

To this:

return "Meow meow";

So now that whole code block looks like this:

 public function meow () {
      return "Meow meow";
 }

526 points
Cc295c27f59e7a8ecc853264009c03c2?s=140&d=retro
Submitted by
melaniesazegar
over 2 years ago