This forum is now read-only. Please use our new forums! Go to forums
Bug? "Oops, try again. I don't see your constructor..."
Is this a bug or am I missing something? I do see “2” echoed in the mini-browser output. 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;
}
}
$teacher = new Person("boring","12345",12345);
$student = new Person("super","dude",2);
echo $student->age;
?>
Answer 559f8222e39efed8850001ed
0 votes
I don’t see any problems in your code, but you can try pasting mine <?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", "asd", 12345);
$student = new Person("boring", "12345", 12345);
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
I guess they expect you to use the “->”, method and and keywords. Time to try something else.