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

Objects in PHP Forum

View Course

432 points
Submitted by
over 2 years ago

8/10 - My code passed but doesn't appear in console - why?

Here's my script. I passed but console says - Parse error: syntax error, unexpected TSTRING, expecting TVARIABLE on line 13.
Why is this? If it's right why doesn't it read in console?
(line 13 is the public function construct name line).

<!DOCTYPE html>

Practice makes perfect!

class Dog {
public $numLegs = 4;
public $name;
public function__construct($name){
$this->name = $name;
public function bark(){
return "Woof!"

    public function greet(){
        return "My name is".$name.";  
   $dog1 = new Dog("Barker");
   $dog2 = new Dog("Amigo");

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


0 votes


in your greet function you have an extra quote marker. instead of:
return "My name is " .$name.";

it could be:
return "My name is $name";


return "My name is " . $name;

additional note here. if you are using single quotes you will need to use the second option. reason: php with read variables within double quotes but not within single quotes.

436 points
Submitted by
Bret Wagner
over 2 years ago