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

Objects in PHP Forum

View Course » View Exercise

572 points
C8758bb07a08819f0435e9e42443a23f?s=140&d=retro
Submitted by
rocket quiah
over 2 years ago

Parse error: syntax error, unexpected T_PUBLIC on line 19

What's wrong with this code? I pass the exercise when I press submit, but only thing on the screen is this message "Parse error: syntax error, unexpected T_PUBLIC on line 19!"

<?php
class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
}
$teacher = new Person();
$student = new Person();
echo $teacher->isAlive;
public function__construct($firstname,$lastname,$age) {
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
}
$teacher = new Person("boring", "12345", 12345);
$student = new Person("Master", "MicroMegas", 99);
echo $teacher->isAlive;
echo $student->age;
?>


1 vote

permalink

You have an extra bracket above $teacher and below $this

693 points
5488dd299113cbfc8b0009ce_504076679
Submitted by
lilsassy
over 2 years ago


0 votes

permalink

add a space after: function, and before: __construct

public function __construct($firstname,$lastname,$age)

717 points
532afe767c82caf100002734_506113534
Submitted by
Thinnling
over 2 years ago


0 votes

permalink

same problem here, but I have the space, anyone ?

<!DOCTYPE html>


Reconstructing the Person Class




<!-- Your code here -->
<?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;
    }

    $teacher = new Person("boring", "12345", 12345);

    $student = new Person("lea", "ma", 45);

    echo $teacher->isAlive;

    echo $student->age;



    ?>
  </p>
</body>

670 points
6998600a4dcac9aad67aba74d5349fa8?s=140&d=retro
Submitted by
leololo
about 2 years ago

1 Comment

Fb0b07781233e09bf24c3e5f2c6593d7?s=140&d=retro Diogo Assunção almost 2 years ago

You need to insert the constructor inside the Object (inside Class Person).