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

Objects in PHP Forum

View Course » View Exercise

114 points
2f9da02fe71d60433c6ae48f76b3a6ff?s=140&d=retro
Submitted by
bmazz
almost 3 years ago

"I don't see your constructor"

<!DOCTYPE html>

Reconstructing the Person Class




<?php
class Person {
public $isAlive = true;

  public $firstname; 
  public $lastname;
  public $age; 

  public function __contruct($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",25);
$student=new Person("boring","12345",23);

 echo $teacher->greet();
 echo $student->greet();

  ?>
  </p>
</body>

1 vote

permalink

change contruct to construct :) it happens no matter how hard you are looking

701 points
Picture
Submitted by
Dimik Jones
almost 3 years ago


0 votes

permalink

you typed contruct instead of construct :D
And also you are missing one curly bracket to close the class person. After closing the
public function greet() {

  return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)"

}

Add one more curly bracket to close the class person :)

646 points
Picture
Submitted by
sunoy14
over 2 years ago

1 Comment

Picture sunoy14 over 2 years ago

And you also forgot to add a semi-colon at the end of
return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)"