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

Objects in PHP Forum

View Course » View Exercise

1073 points
56c6df404a69251081000402_907100238
Submitted by
Ali Marwan
about 2 years ago

5/10 Why it didn't echo my age "28" on the screen and only echo'd "1"

<?php

    class Person{
        public $isAlive=true;
        public $firstname;
        public $lastname;
        public $age;

public function __contruct($firstname, $lastname, $age){ $this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
}
$teacher = new Person("boring", "12345", 12345);
$student = new Person("Ali", "Marwan", 28);
echo $teacher-> isAlive;
echo $student-> age;
?>


1 vote

permalink

here is my code:

<!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("Bruce", "Stones", 29);

        echo $student->age;
    ?>
  </p>
</body>

773 points
54abe5e39113cb92d8001288_889984600
Submitted by
Bruce
about 2 years ago

2 Comments

56c6df404a69251081000402_907100238 Ali Marwan about 2 years ago

thank you

A5ba1285e8142aa3740cc08378e41d6c?s=140&d=retro Reianna-Bryant over 1 year ago

It worked for me too. I took out the "echo $teacher -> isAlive;" part, and it show my age in the panel box.