This forum is now read-only. Please use our new forums! Go to forums
Parse error
My code passes and allows me to proceed, but I’ve had a “parse” error for a few lessons. Can someone help me figure this one out?
The error is: “Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION on line 16”
<!DOCTYPE html>
<html>
<head>
<title> Practice makes perfect! </title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<p>
<?php
class Dog{
public $numLegs = 4;
public $name;
function __construct($nameOfDog){ //line 14
$this->nameOfDog = $name; //line 15
}; //line 16
function bark(){
return "Woof!";
};
function greet(){
return "My name is $name and I'm a talking dog.";
};
};
$dog1 = new Dog("Barker");
$dog2 = new Dog("Amigo");
echo $dog1->bark();
echo $dog2->greet();
?>
</p>
</body>
</html>
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
5 comments
Furthermore, the returned string for the greet() function should be
return “My name is” . $this->name . “and I’m a talking dog.”;
If people actually read the errors.. unexpected ‘;’ says more than enough. I’m glad you knew it by yourself after a while.
You can also use Google for such things. There are thousands of people who ask the same question.
$this->nameOfDog = $name;
should be: $this->name = $nameOfDog;
There are more things wrong in his code, but that wasn’t his question.
You’re right… tons of things are found on Google. This is Codecademy though. The forums here are the first place we should be going to for questions related to these lessons.