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

Objects in PHP Forum

View Course » View Exercise

95 points
29fe006acd07e7f4bbba2628812abe36?s=140&d=retro
Submitted by
meastear
over 2 years ago

Did i have any mistakes?

Did i have any mistakes?
it's says "Oops, try again. I don't see your constructor: Is there a '__construct' 'function'?"

 <?php
      // Your code here
    class Cat {
        public $isAlive = true;
        public $numLegs = 4;
        public $name;
        public function __construct ($name) {
            $this -> name = $name;
        }
        public function meow() {
            echo "Meow meow";
        }
    }

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

    ?>

1 vote

permalink

You should return the "Meow meow" in your meow method instead of echo it.

869 points
2834c430d035e2919ee4ea6fddabd15a?s=140&d=retro
Submitted by
Devan Yu
over 2 years ago


0 votes

permalink

It might be some internal problem. Refreshing the page usually works for me. + you can try to delete the __construct and write it once again. sometimes it helps.

674 points
52fc85d8631fe98202006dc2_575541956
Submitted by
Serge K
over 2 years ago


0 votes

permalink

Thanks, comparing my code with your code helped me through this assignment.

596 points
71c15ab76387ac5ba6529a80914cede8?s=140&d=retro
Submitted by
Ruben van Houten
about 2 years ago