This forum is now read-only. Please use our new forums! Go to forums
why it doesn't work ?
it supposed to echo $student $age which it doesn’t , i just get 1 and i get this message “I don’t see your constructor. Did you also mind the ‘function’ keyword? Please check also, whether you included both underscores (‘__’).” here is my code
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("Mahmoud", "Khamis", 24);
echo $teacher->isAlive;
echo $student->age;
Answer 5489ff94e39efeddd00002f1
0 votes
Hey friend! Remove the $ in your constructor so; public function __construct($fn, $ln, $a){ $this->firstname = $fn; $this->lastname = $ln; $this->age = $a; }
You are refering to an object from the class! :) (or attribute, depends how you look at it really)
Answer 54af80e876b8fe731a0007c3
0 votes
what exactly is it supposed to print? It’s passing the code but printing 124
Thanks!
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
thank you very much ….. i got it .
No problem, glad to help you out, good luck!