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

Objects in PHP Forum

View Course » View Exercise

118 points
795550c037fe1ef02978dad2e968735c?s=140&d=retro
Submitted by
Fiaz Ahmad
almost 3 years ago

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

<?php
    class classname {
        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 classname("tired", "54321", 54321);
    $student = new classname("Jam", "Jok", 26);
    echo $teacher->greet() . '<br>' ;
    echo $student->greet();


    ?>

3 votes

permalink

its $teacher = new classname("boring", "12345", 12345);
not $teacher = new classname("tired", "54321", 54321);

848 points
Picture
Submitted by
Ariel L. Lázaro
almost 3 years ago

4 Comments

Bae928e80b2ca946836c33f1a6aa45e5?s=140&d=retro DSTAT almost 3 years ago

I believe our instructor has a sense of Humor. They want to see "boring" & 12345 for age

Picture ravi.paiyaa over 2 years ago

lol:-)

A03df27bf8726f18a863a1f7ff98e19a?s=140&d=retro anasiqbalkhan over 2 years ago

hahahaha ;)

55747dfc93767665ec000475_986225403 K43 over 2 years ago

I got caught out as well on this after changing the teacher's name to Mr Mong!