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

Objects in PHP Forum

View Course » View Exercise

807 points
Submitted by
almost 3 years ago

Code passes but it doesn't run in the window

This is my code (which passes)

        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


You switched public and function on line 14.

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

814 points
Submitted by
almost 3 years ago

1 Comment

594bd556593c9dcd0239e92c47f1b40f?s=140&d=retro AMR13 almost 3 years ago