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

Objects in PHP Forum

View Course » View Exercise

311 points
Submitted by
about 3 years ago

The code passes but is still doesn't print anything out

The course allows me to pass but the actual code is gving me an error.

The error:
Parse error: syntax error, unexpected T_PUBLIC on line 21

<!DOCTYPE html>
      <title>Reconstructing the Person Class</title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
        class Person {
        public $isAlive = true;
        public $firstname;
        public $lastname;
        public $age;

        public function __constructor($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('Andy', 'Oppenheimer', 16);

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


0 votes


You forgot the closing '}' for the constructor function and had an extra '}' after the end of the class definition
$this->age = $age;
public function greet() {
return "Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)";
$teacher =

134 points
Submitted by
about 3 years ago


711529bebeae041d09f5efaecd1b2c9a?s=140&d=retro PiscesGamer about 3 years ago

Thank You for answering. I eventually realised that I had accidentaly place the greet() function isnide the __constructor().

55a01fd5e39efe4ab700008d_693488337 JollyJuggler02 almost 3 years ago

Yes. Before you post codes for help, make sure that there are no typos within the code. I saw a couple.