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

Objects in PHP Forum

View Course » View Exercise

759 points
Picture
Submitted by
Jono Watkins
over 2 years ago

syntax error, unexpected T_PUBLIC, expecting T_VARIABLE on line 13 but passes?

No displaying anything in the console? I'm confused?

<?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, I'm " . $this.name . ".";
            }
        }    
            $dog1 = new Dog("Barker");
            $dog2 = new Dog("Amigo");

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


    ?>

0 votes

permalink

you have public name,
instead of public name;

450 points
5240e713abf821aa28001257_703076796
Submitted by
Robinvb
over 2 years ago

1 Comment

Picture Jono Watkins over 2 years ago

thank you, sorted


0 votes

permalink

make $this->name instead of $this.name

768 points
52b5acf19c4e9d9f50001991_389654467
Submitted by
khalid92
over 2 years ago