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

Objects in PHP Forum

View Course » View Exercise

874 points
5458be827c82ca6273002603_7147034
Submitted by
butthEd
over 2 years ago

The code passed, but it did not show the right output?

<?php
        class Person {
            public $isAlive = true;
            public $firstname;
            public $lastname;
            public $age;
            public function __constructor($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("dimas", "daras", 16);
    echo $teacher->greet();
    echo $student->greet();
    ?>

As i understood the output for ex. for teacher must be like this :

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

But instead i am getting this :

Hello, my name is " . $this->firstname . " " . $this->lastname . ". Nice to meet you! :-)

Why don't student's property $firstname replace $this->firstname?


5 votes

Best answer

permalink

LOL guys i've found it. Instead of writing public function __construct, I wrote public function __constructor. So be attentive, when coding.

874 points
5458be827c82ca6273002603_7147034
Submitted by
butthEd
over 2 years ago

3 Comments

54c68b3a9113cb1e5200035f_114210188 Ojas Rajwansh over 2 years ago

due ur triipy

54c68b3a9113cb1e5200035f_114210188 Ojas Rajwansh over 2 years ago

*dude

206a34368cf60f7ea397e82b6ad26114?s=140&d=retro Matthew Aldaco about 2 years ago

... Thanks for telling us. I still feel sad though.