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

Objects in PHP Forum

View Course » View Exercise

341 points
Picture
Submitted by
saagar
over 2 years ago

Why I'm getting unexpected } and also not showing the output?

<!DOCTYPE html>


Reconstructing the Person Class




<?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("boring", "12345", 12345);
    $student = new Person("dude", "perfect", 24);
    echo $student->greet();
    echo $teacher->greet();
    ?>
  </p>
</body>

-1 votes

permalink

Because you've forgetten to type semicolon ';' in the greet() function.

686 points
9a60e17395e12f0b1698491eb02d15fa?s=140&d=retro
Submitted by
assenov
over 2 years ago