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

Objects in PHP Forum

View Course » View Exercise

491 points
890f676f4073ac1ed1dda19b865ee705?s=140&d=retro
Submitted by
Dhawalgupta
over 2 years ago

ERROR

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

This error is annoying me again and again dont know why its coming I have added it still. Help ASAP.

Code:public function__construct($firstname,$lastname,$age) {
$this->firstname=$firstname;
$this->lastname=$lastname;
$this->age=$age;
$this->myname=$myname;
} }
$teacher=new Person ("tired","12345",22);
$student=new Person ("Dhawan","Gupta",20);
echo $teacher->isAlive;
echo $student->age;


1 vote

permalink

Hi you write at :
$student=new Person ("Dhawan","Gupta",20);
your datas, but you have to write your commands like this:
$student = new Person($firstname, $lastname, $age);

Here i write you my code, this should work.

<!DOCTYPE html>


Reconstructing the Person Class




<!-- Your code here -->
<?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("boring", "12345", 12345);
    $student = new Person($firstname, $lastname, $age);
  echo $teacher->isAlive;
  echo $student->age;

  ?>
  </p>
</body>

I hope this will help you

your sincerly xMichix

514 points
Cbadd5f534ea698d0f4a98fc15b20a64?s=140&d=retro
Submitted by
xMichi1996x
over 2 years ago


0 votes

permalink

I'm stuck at this same point. The ":-P" doesn't help very much, either. :-/

853 points
5521b6a793767601cf000242_592435835
Submitted by
rishanka
over 2 years ago

2 Comments

5521b6a793767601cf000242_592435835 rishanka over 2 years ago

Huh, weird. I refreshed the page, changed the teacher name from "Boring" to "boring", and it worked!

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

890f676f4073ac1ed1dda19b865ee705?s=140&d=retro Dhawalgupta over 2 years ago

This also doesnot help making things "boring". What is the problem can anyone answer that.I changed the teacher name from "tired"->"boring".


0 votes

permalink

It worked but i guess there is a bug in this excercise,because i wasnt able to see the output .But yes it compiled and showed no errors.

491 points
890f676f4073ac1ed1dda19b865ee705?s=140&d=retro
Submitted by
Dhawalgupta
over 2 years ago