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

Objects in PHP Forum

View Course » View Exercise

807 points
594bd556593c9dcd0239e92c47f1b40f?s=140&d=retro
Submitted by
AMR13
about 2 years ago

Code passes but it doesn't run in the window

This is my code (which passes)

    <?php
        class Dog {
            public $numLegs = 4;
            public $name;

            function public __construct($name) {
                $this->name = $name;
            }

            public function bark() {
                return "Woof!";
            }

            public function greet() {
                return "Hi, my name is " . $this->name . " !"
            }
        }

        $dog1 = new Dog("Barker");
        $dog2 = new Dog("Amigo");

        echo $dog1->bark();
        echo $dog2->greet();
    ?>

But the window shows

""Parse error: syntax error, unexpected TPUBLIC, expecting TSTRING on line 14""

Please help me out, Thanks.


0 votes

permalink

You switched public and function on line 14.

"function public _construct($name)" should be "public function _construct($name)"

814 points
955ab9d134b5bd63ea6a7bdd7eb06f1e?s=140&d=retro
Submitted by
ValdezBoy
about 2 years ago

1 Comment

594bd556593c9dcd0239e92c47f1b40f?s=140&d=retro AMR13 about 2 years ago

Thanks.