This forum is now read-only. Please use our new forums! Go to forums
Objects in PHP 5/10
Can’t figure out what I am doing wrong. Shows unexpected syntax ‘}” on line 22. Any pointers?
Answer 53eb2dc5631fe9d48400155c
Seems as you opened “{“ twice and only closed it once.
“class Person { “ and “public function _construct($firstname,$lastname,$age){“ and only closed it at “$this->age = $age; }”
I used the following code which was correct: <?php class Person { $teacher = new person (“boring”, “12345”, “12345”); $student = new person (“Hello”, “Bye”, “12”); public $isAlive = true; public $firstname = ; public $lastname = ; public $age = ; } echo $teacher $isAlive; echo $student $age;
public function __construct ($firstname, $lastname, $age) {
$this -> fristname = $firstname;
$this -> lastname = $lastname;
$this -> age = $age;
}
?>
Answer 53fcb5f8631fe91cf1000519
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("Vasile","Tonofa",19);
echo $student->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
1 comments
Thanks : )