This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Objects in PHP Forum

View Course » View Exercise

618 points
Picture
Submitted by
Andrew Lim
over 2 years ago

Oops, try again. I don't see your constructor.

<?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("Alex", "Choh", 39);
$student = new Person("Andrew", "Lim", 20);
echo $teacher->greet();
echo $student->greet();
?>


0 votes

permalink

Hi Andrew,

Which exercise are you on?

2819 points
5674c6dae39efec455000434_879409444
Submitted by
Zeke Y
over 2 years ago


0 votes

permalink

__construct

Copy the above and paste it in the write place the command should be. It will work!

260 points
Picture
Submitted by
Randy Smith
over 2 years ago