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

Objects in PHP Forum

View Course » View Exercise

411 points
0edcc6fe3cf795eb6e9c63b649283a2c?s=140&d=retro
Submitted by
andrewnoelcasper
over 2 years ago

General Question

Hello! So I was working on 9/10 and I passed it but what i didnt understand is when I tried to echo $cat1 it didnt show in the console. Is it a bug? Or is it my code?
Here is my code.
class Cat {
public $isAlive = true;
public $numLegs = 4;
public $name;
public function __construct($name) {
$this->name = $name;
}
public function meow() {
return "" . $this->$name . "Meow meow";

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

Thank you.


3 votes

permalink

in the meow method you wrote " $this->$name " , remove the $ for the name. just like this ---> " $this->name ".
hope it works :)

850 points
547dcfd29c4e9d6a5700238c_768950481
Submitted by
Sarah
over 2 years ago

1 Comment

0edcc6fe3cf795eb6e9c63b649283a2c?s=140&d=retro andrewnoelcasper over 2 years ago

Thanks :)