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

Objects in PHP Forum

View Course » View Exercise

612 points
5551c8ac51b887455800037b_893462519
Submitted by
Rob Sarna
about 4 years ago

Cant get it working :( - Parse error: syntax error, unexpected T_OBJECT_OPERATOR on line 34

It passes the course but i get this error

Parse error: syntax error, unexpected T_OBJECT_OPERATOR on line 34

 <?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." and i like Dog food!";

            }
        }

       $dog1 = new Dog(

           $name="Barker"
       );

       $dog2 = new Dog(

           $name="Amigo"
       );

       echo $dog2->greet();



        ?>

Alex J edited this post to fix code formatting


0 votes

permalink

It would have been very helpful if you told us which line is the 34th one. However I'm guessing that the source of your error is in the greet function:

this->$name doesn't make sense. Should be $this->name instead.

3117 points
Picture
Submitted by
Alex J
about 4 years ago


0 votes

permalink

here this works!
<?php
class Dog {
public $numLegs = 4;
public $name;
public function __construct($name){
$this->name = $name;
}
}
?>

554 points
519a2e4a05dfa31a36003047_35877524
Submitted by
Joseph
about 4 years ago