This forum is now read-only. Please use our new forums! Go to forums
Codecademy accepts exercise, but the build-in browser shows a mistake
Written code
<!DOCTYPE html>
<html>
<head>
<title>Reconstructing the Person Class</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<p>
<!-- Your code here -->
<?php
class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
public function __construct($firstname, $lastname,$age) {
this->$firstname = $firstname ;
this->$lastname = $lastname ;
this->$age = $age;
}
};
$teacher = new Person('boring','12345','12345');
$student = new Person('smart', '54321','54321');
echo $teacher->isAlive;
echo $student->age;
?>
?>
?
</p>
</body>
</html>
and browser prints out
Parse error: syntax error, unexpected T_OBJECT_OPERATOR on line 17
17th line is this->$firstname = $firstname ;
Answer 55c0be6c937676953c00078c
1 vote
yes you have to write: this->firstname = $firstname ; you have to correct the same at line 18 and 19
I hope this will help
Answer 55c2d4f5937676772f000340
1 vote
you have yer $ in the wrong place. you want something like
public function __construct($firstname, $lastname,$age) { $this->firstname = $firstname ; $this->lastname = $lastname ; $this->age = $age; }
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