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

Objects in PHP Forum

View Course » View Exercise

743 points
818faff5a19b23e64c8d59652926e5a6?s=140&d=retro
Submitted by
MikeRuderisch
about 2 years ago

Objects in PHP 6/10

I need help... I can't find my mistake.. :(

class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
public function greet() {
return "Hello, my name is ".$this->firstname." ".$this->lastname.". Nice to meet you! :-)";
}

  public  function __construct($firstname, $lastname, $age) {
    $this->firstname = $firstname;
    $this->lastname = $lastname;
    $this->age = $age;
  }
}

  $teacher = new Person("boring", "12345", 12345);
  $student = new Person("Mike", "Ruderisch", 16);
  echo $teacher->isAlive;
  echo $student->age;
  echo $student->greet();
  echo $teacher->greet();

?>

0 votes

permalink

Hi Mike,

Your code worked fine for me. If refreshing the page doesn't work for you, could you tell me what the error message you're getting says?

2818 points
5674c6dae39efec455000434_879409444
Submitted by
Zeke Y
about 2 years ago


0 votes

permalink

hey in the return line please compare this code
return"hello my name is" .$this->firstname."".$this->$lastname."nice to meet you!:)".; you will find mistake if not please refresh the page

111 points
1f96b188244043de81be32d891b99e5e?s=140&d=retro
Submitted by
str111
about 2 years ago