This forum is now read-only. Please use our new forums! Go to forums
6/10 Parse error: syntax error, unexpected '}', expecting T_STRING on line 22
Hi, I get the above error regarding the ending ‘}’ of my greet function (line 22). Can anyone point out where my code has gone wrong? Thanks!
<?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;
}
public function greet() {
return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
}
}
$teacher = new Person("boring", "12345", 12345);
$student = new Person("exciting", "magick", 12345);
echo $student->greet();
echo $teacher->greet();
?>
Answer 552ecd7f937676c5a4000419
0 votes
It seems to have fixed itself since I exited and reopened my browser! :-)
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
2 comments
Hey, did you forget add my name as a property to the object? :-P
I found this error when I submit the code
i pass with this error message, but it does not go away when I take “echo $teacher -> isAlive; echo $student -> age;” out. I refreshed my browser, and it is still there. What is up?