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

Objects in PHP Forum

View Course » View Exercise

627 points
055e3c8658ac3d83a4fc8f05982f0bf6?s=140&d=retro
Submitted by
Adrian Rajkamal
about 2 years ago

Weird Answer...help!

Hi, HI have passed 6/10 but...it comes up weird, here's what I'm getting:

114Hello, my name is boring 12345. Nice to meet you! :-)Hello, my name is Adrian Rajkamal. Nice to meet you! :-)

is it supposed to be like this? Here's my 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! :-)";
        }
    }
    $teacher = new Person("boring", "12345", 12345);
    $student = new Person("Adrian", "Rajkamal", 14);
    echo $teacher->isAlive;
    echo $student->age;
    echo $teacher -> greet();
    echo $student -> greet();
    ?>

0 votes

permalink

Yes, it is supposed to be like this. Your code is correct.

echo $teacher->isAlive; -> 1
echo $student->age; -> 14
echo $teacher -> greet(); -> Hello, my name is boring 12345. Nice to meet you! :-)
echo $student -> greet(); -> Hello, my name is Adrian Rajkamal. Nice to meet you! :-)

686 points
9a60e17395e12f0b1698491eb02d15fa?s=140&d=retro
Submitted by
assenov
about 2 years ago

1 Comment

055e3c8658ac3d83a4fc8f05982f0bf6?s=140&d=retro Adrian Rajkamal about 2 years ago

ok thankyou!