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

Objects in PHP Forum

View Course » View Exercise

320 points
53ccd272548c35be3000153f_913045494
Submitted by
Lou Delgado
almost 3 years ago

what is wrong with my code? 1.4 Property Panic

This is what I have!
class Person {
public $isalive = "true";
public $firstname;
public $lastame;
public $age;
}
$teacher = new Person();
$student = new Person();
echo $teacher->isalive;

I get "true" in green letters as my answer. I've also tried the variation $isAlive but that gives me a fatal error message swell. What am I missing!!??


2 votes

permalink

you quoted "true" which makes it a string. remove quotes to make it Boolean...

1759 points
52131f8c80ff33cef500003b_188347261
Submitted by
7z4r
almost 3 years ago

2 Comments

53ccd272548c35be3000153f_913045494 Lou Delgado almost 3 years ago

I've tried that it out puts the number one and still refuses to pass me

5ea9b80f809dedb8a96974824cf76a6c?s=140&d=retro Ian Grigg almost 3 years ago

I have run into the error that if I didn't copy exactly what is in the lesson, it wouldn't pass me. In your case is it the $isAlive variable missing the upper case 'A' in alive?


1 vote

permalink

This worked for me.

class Person {
public $isAlive = true;

public $firstname;
public $lastname;
public $age;
}
$teacher = new Person ();
$student = new Person ();
$sAlive = new Person ();
echo $teacher->isAlive;
?>

1228 points
52f07fbc548c358e90000e1a_385034243
Submitted by
carlosmante
over 2 years ago

1 Comment

5e45261baebb9cf0e052a7d324880e91?s=140&d=retro SexyBro about 2 years ago

Thank you, now it accepted it. I just needed an extra line between the defined variable and the undefined ones. The parsing algorithms on this site are extremely picky.


0 votes

permalink

echo $teacher->isAlive;

try this

542 points
53a474e1282ae3bbd1000aa5_293264960
Submitted by
Salman Kazmi
almost 3 years ago