This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by MikeRuderisch
almost 9 years

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();

?>

Answer 5560fcc79113cb3bee00027b

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?

points
Submitted by Zeke Y
almost 9 years

Answer 5566ac38937676005a000040

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

points
Submitted by str111
almost 9 years