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

Objects in PHP Forum

View Course » View Exercise

305 points
55fffe099113cb789d0005f7_873335901
Submitted by
Axl
about 2 years ago

Error: Oops, try again. Hey, did you forget add my name as a property to the object? :-P

Hi guys,

I'm blind right now. Can you please help :D.

  <p>
    <!-- Your code here -->
    <?php
    class Person {
        public $isAlive = true;
        public $firstname;
        public $lastname;
        public $age;

        public function __construct($firstname, $lastname, $age) {
        $this->name = $firstname;
        $this->surname = $lastname;
        $this->age = $age;
    }
    }
    $teacher = new Person(" Hank", " Moody ", 58);
    $student = new Person(" Sasha ", "Bingham ", 17);


    echo $student->name;
    echo $student->surname;
    echo $student->age;
    echo $teacher->name;
    echo $teacher->surname;
    echo $teacher->age;

    ?>
  </p>
</body>

0 votes

permalink

nevermind :D. code requires you to use this as the teacher's name, age etc.:

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

305 points
55fffe099113cb789d0005f7_873335901
Submitted by
Axl
about 2 years ago