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

Objects in PHP Forum

View Course » View Exercise

640 points
524cc24c80ff3309cb006288_369387522
Submitted by
Jeremy Polen
over 2 years ago

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

I am getting the same error message back also. I have my greet() function and function __construct() in side of my class Person. My preview window seems to be displaying the correct info. I need help as well, can anyone lend a hand?

Here is my current code:

<?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;
    }
    public function greet() {
        return "Hello, my name is " . $this->firstname . " "                 . $this->lastname . ". Nice to meet you! :-)";
    }
    public function tellage() {
       return $this->firstname . " is " . $this->age . " years old.";
    }
}

    $teacher = new Person("Boring", "Adult", 55);
    $student = new Person("First", "Last", 24);

    echo $teacher->greet() . "<br />";
    echo $student->greet() . "<br />";
    echo $teacher -> tellage() . "<br />";
    echo $student -> tellage() . "<br />";
?>

Thank you for your time and consideration.


0 votes

permalink

I figured the issue. You have to type "boring" exactly like that, not "BORING, Boring, or any other combination. This lesson is looking for that information to be exact or else it says it is incorrect.

Below is a snippet of that line:

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

And here is my now working code:
(NOTICE: I have added a bit that tells the age also just for practice, this can be included and still get a correct answer but is not necessary.)

    <?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;
        }
        public function greet() {
            return "Hello, my name is " . $this->firstname . " "                 . $this->lastname . ". Nice to meet you! :-)";
        }
        public function tellage() {
           return $this->firstname . " is " . $this->age . " years old.";
        }
    }

        $teacher = new Person("boring", "12345", 12345);
        $student = new Person("Jeremy", "Polen", 24);

        echo $teacher->greet() . "<br />";
        echo $student->greet() . "<br />";

        echo $teacher -> tellage() . "<br />";
        echo $student -> tellage() . "<br />";
    ?>

640 points
524cc24c80ff3309cb006288_369387522
Submitted by
Jeremy Polen
over 2 years ago