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

Objects in PHP Forum

View Course » View Exercise

392 points
23d96d09161a57470061488a85bbba2e?s=140&d=retro
Submitted by
dheijman
about 3 years ago

Keep getting a loading icon in the middle of my screen, or in the preview screen

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

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

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

            public function greet(){
                return "Hello! My name is " . $this->name . ". What's yours?";
            }

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

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

    ?>

It'll probably be a silly question, but I can't seem to figure it out! Thanks!


0 votes

permalink

closing parenthesis of class Dog must be after public function greet(), constructor and method must be inside the class Dog

701 points
Picture
Submitted by
Dimik Jones
about 3 years ago