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

Objects in PHP Forum

View Course » View Exercise

610 points
Ce9d67d67898f2ef2d4e71d81f6cb052?s=140&d=retro
Submitted by
MatthiasBekaert
over 2 years ago

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

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

<!DOCTYPE html>
<html>
<head>
  <title>Reconstructing the Person Class</title>
  <link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
  <p>
    <?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("Matthias","Bekaert", 20);
        $student = new Person("Maias","Bert", 12);

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

I don't have any errors, so I don't know what I do wrong...


2 votes

permalink

You just need to set name, lastname and age for $teacher as stated in the task:

Change your $teacher instantiation to
store new Person("boring", "12345",12345).

So it should be $teacher = new Person("boring","12345", 12345);

674 points
52fc85d8631fe98202006dc2_575541956
Submitted by
Serge K
over 2 years ago

2 Comments

Ce9d67d67898f2ef2d4e71d81f6cb052?s=140&d=retro MatthiasBekaert over 2 years ago

Thanks! It worked

55061fff9113cbcaab007221_388739080 Islam Sabr over 2 years ago

But this is a bit confusing and though idea. It should accept any value, after finishing this course there will be no need to add your name, you should teach what people need and want to know not vice versa.


2 votes

permalink

For anyone else who is having this problem, you should make sure boring is not capitalized.

$teacher = new person("Boring", "12345", 12345);

will not pass, but:

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

630 points
47a42e5f695548436bbba4afd2d512a0?s=140&d=retro
Submitted by
Joshua Paxton
over 2 years ago


-1 votes

permalink

Delete this echo "$teacher->isAlive;"

539 points
Fb38264f0f0d46a1e77c7d0532af5f72?s=140&d=retro
Submitted by
yzmt
over 2 years ago